From 6ba50c2d1e0e5838a29c56e0183a251efa044c06 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 28 Apr 2014 16:16:03 +0200 Subject: [PATCH] Fixed GetComponent bug which would create invalid components if the entity didn't have the requested component --- src/World.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/World.h b/src/World.h index 255ef1b..ffe887d 100755 --- a/src/World.h +++ b/src/World.h @@ -138,7 +138,16 @@ std::shared_ptr World::AddComponent(EntityID entity, std::string componentTyp template T* World::GetComponent(EntityID entity, std::string componentType) { - return (T*)m_EntityComponents[entity][componentType].get(); + auto components = m_EntityComponents[entity]; + auto it = components.find(componentType); + if (it != components.end()) + { + return static_cast(it->second.get()); + } + else + { + return nullptr; + } } #endif // World_h__ \ No newline at end of file