From 0b8a3230c308aed83c307ffcd15dfebe130e2a6e Mon Sep 17 00:00:00 2001 From: Stiffly Date: Mon, 28 Apr 2014 16:18:08 +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 d0c0692..8829933 100755 --- a/src/World.h +++ b/src/World.h @@ -135,7 +135,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