From 8ee880c6deadcd02e122a41a8e23e0ffd17adb2b Mon Sep 17 00:00:00 2001 From: Nat Weiss Date: Sat, 23 May 2015 23:47:44 -0700 Subject: [PATCH] Check if entity exists before adding / removing component. --- EntityFu.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EntityFu.cpp b/EntityFu.cpp index 81db9b4..e6e6a38 100644 --- a/EntityFu.cpp +++ b/EntityFu.cpp @@ -124,7 +124,7 @@ void Entity::addComponent(Cid cid, Eid eid, Component* c) { if (c == nullptr) return; - if (eid >= kMaxEntities || cid >= Component::numCids) + if (eid >= kMaxEntities || !entities[eid] || cid >= Component::numCids) { Assert2(false, "Invalid eid %u or cid %u", eid, cid); return; @@ -153,7 +153,7 @@ void Entity::addComponent(Cid cid, Eid eid, Component* c) void Entity::removeComponent(Cid cid, Eid eid) { - if (eid >= kMaxEntities || cid >= Component::numCids) + if (eid >= kMaxEntities || !entities[eid] || cid >= Component::numCids) { Assert2(false, "Invalid eid %u or cid %u", eid, cid); return;