[scene] Ensure entity owns component before removing

I realized I should check that the entity owns the component before
treating it as existing when adding an existing component, then noticed
that Ent_RemoveComponent didn't check before removing the component. I
imagine that would have been a fun debug session :P
This commit is contained in:
Bill Currie 2022-10-25 09:55:08 +09:00
parent 9e83ded0ac
commit 4759be449f

View file

@ -97,7 +97,7 @@ Ent_RemoveComponent (uint32_t ent, uint32_t comp, ecs_registry_t *registry)
uint32_t id = Ent_Index (ent);
ecs_pool_t *pool = &registry->comp_pools[comp];
uint32_t ind = pool->sparse[id];
if (ind < pool->count) {
if (ind < pool->count && pool->dense[ind] == ent) {
uint32_t last = pool->count - 1;
Component_DestroyElements (&registry->components[comp], pool->data,
ind, 1);