mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-20 07:50:45 +00:00
[ecs] Delay calculation of last index
Removing a hierarchy from an entity can result in a large number of component removes in the same pool, thus changing index of the lest element of the pool. This *seems* to fix the memory corruption I've been experiencing with the debug UI.
This commit is contained in:
parent
71bc708030
commit
7e338b7e29
1 changed files with 1 additions and 1 deletions
|
@ -116,7 +116,6 @@ Ent_RemoveComponent (uint32_t ent, uint32_t comp, ecs_registry_t *registry)
|
|||
uint32_t ind = pool->sparse[id];
|
||||
component_t *c = ®istry->components.a[comp];
|
||||
if (ind < pool->count && pool->dense[ind] == ent) {
|
||||
uint32_t last = pool->count - 1;
|
||||
// invalidate the entity for this component to prevent the component
|
||||
// being double-removed due to deletion of the component resulting
|
||||
// in the entity being deleted (happens with hierarchies)
|
||||
|
@ -137,6 +136,7 @@ Ent_RemoveComponent (uint32_t ent, uint32_t comp, ecs_registry_t *registry)
|
|||
}
|
||||
}
|
||||
}
|
||||
uint32_t last = pool->count - 1;
|
||||
if (last > ind) {
|
||||
pool->sparse[Ent_Index (pool->dense[last])] = ind;
|
||||
pool->dense[ind] = pool->dense[last];
|
||||
|
|
Loading…
Reference in a new issue