mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-11 07:42:18 +00:00
[ecs] Make Ent_HasComponent more robust
It doesn't check that the entity itself is valid, but it does at least check that the index fetched from the sparse array is valid. Fixes a segfault when a valid entity never had the component.
This commit is contained in:
parent
7c06012383
commit
962319af09
1 changed files with 3 additions and 2 deletions
|
@ -198,8 +198,9 @@ ECS_EntValid (uint32_t id, ecs_registry_t *reg)
|
|||
COMPINLINE int
|
||||
Ent_HasComponent (uint32_t ent, uint32_t comp, ecs_registry_t *reg)
|
||||
{
|
||||
uint32_t ind = reg->comp_pools[comp].sparse[Ent_Index (ent)];
|
||||
return reg->comp_pools[comp].dense[ind] == ent;
|
||||
ecs_pool_t *pool = ®->comp_pools[comp];
|
||||
uint32_t ind = pool->sparse[Ent_Index (ent)];
|
||||
return ind < pool->count && pool->dense[ind] == ent;
|
||||
}
|
||||
|
||||
COMPINLINE void *
|
||||
|
|
Loading…
Reference in a new issue