Skip to content

Commit

Permalink
Check if entity exists before adding / removing component.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nat Weiss committed May 24, 2015
1 parent 69edca4 commit 8ee880c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions EntityFu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8ee880c

Please sign in to comment.