Fixed #49 being able to parent an entity to itself, which resulted in infinite infinite loops everywhere! D:

This commit is contained in:
2016-01-27 18:06:33 +01:00
parent 65da634c71
commit 13f020ddf5
2 changed files with 8 additions and 1 deletions
+7
View File
@@ -96,6 +96,13 @@ EntityID World::GetParent(EntityID entity)
void World::SetParent(EntityID entity, EntityID parent)
{
// Don't allow an entity to be a child to itself!
if (entity == parent) {
// HACK: We purposely don't check the whole hierarchy of children here, since it would be way too slow.
// This might result in infinite loops if an entity somehow ends up as a child.
return;
}
EntityID lastParent = m_EntityParents.at(entity);
auto parentChildren = m_EntityChildren.equal_range(lastParent);
for (auto it = parentChildren.first; it != parentChildren.second; it++) {