[ecs] Avoid shuffling components in empty ranges

When bubbling a component past an empty range, there's no need for any
actual movement other than adjusting the range itself, and doing so
corrupts the sparse/dense array relationship. Fixes a segfault when
hiding the deathmatch overlay (that resulted from the change to using
canvases).
This commit is contained in:
Bill Currie 2023-01-21 13:58:43 +09:00
parent 03e867f0f8
commit 3d52caadec

View file

@ -123,10 +123,12 @@ Ent_RemoveComponent (uint32_t ent, uint32_t comp, ecs_registry_t *registry)
while (range - subpool->ranges < range_count) {
uint32_t end = --*range;
range++;
pool->sparse[Ent_Index (pool->dense[end])] = ind;
pool->dense[ind] = pool->dense[end];
Component_MoveElements (c, pool->data, ind, end, 1);
ind = end;
if (ind < end) {
pool->sparse[Ent_Index (pool->dense[end])] = ind;
pool->dense[ind] = pool->dense[end];
Component_MoveElements (c, pool->data, ind, end, 1);
ind = end;
}
}
}
if (last > ind) {