From 9d5c737cd6b8e772a5856dbe7e20ab4a3394f649 Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Wed, 2 Aug 2023 15:34:35 -0400 Subject: [PATCH] Fixed entity cache not clearing --- Nuake/src/Scene/Scene.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index 79e022b8..72a423fe 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -77,10 +77,10 @@ namespace Nuake { Entity Scene::GetEntityByID(int id) { - //if (m_EntitiesIDMap.find(id) != m_EntitiesIDMap.end()) - //{ - // return m_EntitiesIDMap[id]; - //} + if (m_EntitiesIDMap.find(id) != m_EntitiesIDMap.end()) + { + return m_EntitiesIDMap[id]; + } auto idView = m_Registry.view(); for (auto e : idView) @@ -273,11 +273,15 @@ namespace Nuake { for (auto& c : copyChildrens) { - Logger::Log("Deleting entity " + std::to_string(c.GetHandle())); DestroyEntity(c); } - Logger::Log("Deleted entity" + std::to_string(entity.GetHandle()) + " - " + entity.GetComponent().Name); + // Remove from ID to Entity cache + if (m_EntitiesIDMap.find(entity.GetComponent().ID) != m_EntitiesIDMap.end()) + { + m_EntitiesIDMap.erase(entity.GetComponent().ID); + } + entity.Destroy(); m_Registry.shrink_to_fit(); }