Fixed #49 being able to parent an entity to itself, which resulted in infinite infinite loops everywhere! D:
This commit is contained in:
@@ -96,6 +96,13 @@ EntityID World::GetParent(EntityID entity)
|
|||||||
|
|
||||||
void World::SetParent(EntityID entity, EntityID parent)
|
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);
|
EntityID lastParent = m_EntityParents.at(entity);
|
||||||
auto parentChildren = m_EntityChildren.equal_range(lastParent);
|
auto parentChildren = m_EntityChildren.equal_range(lastParent);
|
||||||
for (auto it = parentChildren.first; it != parentChildren.second; it++) {
|
for (auto it = parentChildren.first; it != parentChildren.second; it++) {
|
||||||
|
|||||||
@@ -759,7 +759,7 @@ void EditorGUI::entityDelete(EntityWrapper entity)
|
|||||||
|
|
||||||
void EditorGUI::entityChangeParent(EntityWrapper entity, EntityWrapper parent)
|
void EditorGUI::entityChangeParent(EntityWrapper entity, EntityWrapper parent)
|
||||||
{
|
{
|
||||||
if (entity == parent) {
|
if (entity == parent || parent.IsChildOf(entity)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user