Skip to content

Commit

Permalink
Merge pull request #3 from MAUSMAUSgames/patch-1
Browse files Browse the repository at this point in the history
minor changes to addComponent/removeComponent
  • Loading branch information
NatWeiss committed May 23, 2015
2 parents ce4afd9 + 8851e3d commit baf7d9e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions EntityFu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ void Entity::addComponent(Eid eid, Component* c, Cid cid)
Entity::log(cid);
Log("Adding component cid %u eid %u (%x)", cid, eid, (int)(long)c);
}


// if component already added, delete old one
auto ptr = components[cid][eid];
if (ptr != nullptr)
delete ptr;

// pointers to components are stored in the map
// (components must be allocated with new, not stack objects)
components[cid][eid] = c;
Expand Down Expand Up @@ -199,9 +204,8 @@ void Entity::removeComponent(Eid eid, Cid cid)
Log("Removing component cid %u eid %u (%x)", cid, eid, (int)(long)ptr);
}

// pointers to components are deleted
if (ptr != nullptr)
delete ptr;
// pointers to components are deleted, no need to check if nullptr because of line 197-198
delete ptr;

// erase the component pointer
components[cid][eid] = nullptr;
Expand Down

0 comments on commit baf7d9e

Please sign in to comment.