This commit is contained in:
Lars Mueller 2024-01-06 14:41:30 +01:00
parent bd9f3aaa52
commit 5591964b2b
1 changed files with 10 additions and 7 deletions

View File

@ -277,8 +277,9 @@ namespace scene
child->grab(); child->grab();
child->remove(); // remove from old parent child->remove(); // remove from old parent
Children.push_back(child); Children.push_back(child);
child->Iterator = Children.end(); // Note: This iterator is not invalidated until we erase it.
(*child->Iterator)--; child->ThisIterator = Children.end();
--(*child->ThisIterator);
child->Parent = this; child->Parent = this;
} }
} }
@ -294,8 +295,9 @@ namespace scene
if (child->Parent != this) if (child->Parent != this)
return false; return false;
auto it = child->Iterator.value(); // The iterator must be set since the parent is not null.
child->Iterator = std::nullopt; auto it = *child->ThisIterator;
child->ThisIterator = std::nullopt;
child->Parent = nullptr; child->Parent = nullptr;
child->drop(); child->drop();
Children.erase(it); Children.erase(it);
@ -311,7 +313,7 @@ namespace scene
{ {
for (auto &child : Children) { for (auto &child : Children) {
child->Parent = nullptr; child->Parent = nullptr;
child->Iterator = std::nullopt; child->ThisIterator = std::nullopt;
child->drop(); child->drop();
} }
Children.clear(); Children.clear();
@ -617,11 +619,12 @@ namespace scene
//! Pointer to the parent //! Pointer to the parent
ISceneNode* Parent; ISceneNode* Parent;
std::optional<ISceneNodeList::iterator> Iterator;
//! List of all children of this node //! List of all children of this node
std::list<ISceneNode*> Children; std::list<ISceneNode*> Children;
//! Iterator pointing to this node in the parent's child list.
std::optional<ISceneNodeList::iterator> ThisIterator;
//! Pointer to the scene manager //! Pointer to the scene manager
ISceneManager* SceneManager; ISceneManager* SceneManager;