From c64d621f0ed1668accd53935ae2e7cb2c4747176 Mon Sep 17 00:00:00 2001 From: Mergul Date: Tue, 26 Mar 2019 13:13:32 +0000 Subject: [PATCH] -fixed critical bug with onAdd callback --- source/ecs/manager.d | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/source/ecs/manager.d b/source/ecs/manager.d index 7c10e5e..0c6d0aa 100644 --- a/source/ecs/manager.d +++ b/source/ecs/manager.d @@ -1941,16 +1941,19 @@ class EntityManager foreach (block; thread.blocks_to_update) { EntityInfo* info = block.type_info; - if(info.add_listeners) - { - callAddEntityListeners(info,block,block.entities_count,block.entities_count+block.added_count); - } + ushort entities_count = block.entities_count; block.entities_count += block.added_count; if (block.entities_count > block.type_info.max_entities) { block.entities_count = block.type_info.max_entities; } block.added_count.atomicStore(cast(ushort) 0); + + if(info.add_listeners) + { + callAddEntityListeners(info,block,entities_count,block.entities_count); + } + } thread.blocks_to_update.clear(); }