From 75171743a448d57c1fbcd0960183f6bba3f862ab Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 26 Dec 2023 11:10:07 +0900 Subject: [PATCH] [ecs] Destroy component pools in reverse order This seems to be the best solution for interlinked entities/components, the idea being that components with higher indices can "own" those with lower (eg, imui_reference can "own" a view_href, but not the other way) and makes it relatively easy to manage (components that can own others get added to the registry later), and might even allow validation at a later stage. --- libs/ecs/ecs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/ecs/ecs.c b/libs/ecs/ecs.c index b00c85422..86f28a0d8 100644 --- a/libs/ecs/ecs.c +++ b/libs/ecs/ecs.c @@ -50,10 +50,11 @@ ECS_DelRegistry (ecs_registry_t *registry) return; } registry->locked = 1; - for (uint32_t i = 0; i < registry->components.size; i++) { + for (uint32_t i = registry->components.size; i-- > 0 ;) { __auto_type comp = ®istry->components.a[i]; __auto_type pool = ®istry->comp_pools[i]; Component_DestroyElements (comp, pool->data, 0, pool->count); + pool->count = 0; } free (registry->entities); for (uint32_t i = 0; i < registry->components.size; i++) {