[ecs] Invalidate entity in hierarchy before removal

I'm not sure just what was going on other than *other* components were
getting double-removed when the hierarchy reference component was
removed when the entity was being deleted. This might even prevent
issues with removing the hierarchy from an entity that's not being
deleted as the pre-invalidation prevents the removal from deleting the
entity.
This commit is contained in:
Bill Currie 2023-03-07 02:00:19 +09:00
parent f12b3ea134
commit 00d1ae0b91
2 changed files with 4 additions and 0 deletions

View file

@ -205,6 +205,9 @@ ECS_NewEntity (ecs_registry_t *registry)
VISIBLE void
ECS_DelEntity (ecs_registry_t *registry, uint32_t ent)
{
if (!ECS_EntValid (ent, registry)) {
return;
}
if (registry->locked) {
// the registry is being deleted and mass entity and component
// deletions are going on

View file

@ -482,6 +482,7 @@ Hierref_DestroyComponent (void *href)
{
hierref_t ref = *(hierref_t *) href;
if (ref.hierarchy) {
ref.hierarchy->ent[ref.index] = -1;
Hierarchy_RemoveHierarchy (ref.hierarchy, ref.index, 1);
if (!ref.hierarchy->num_objects) {
Hierarchy_Delete (ref.hierarchy);