Browse Source

Add comment to Node::RemoveChild().

Lasse Öörni 8 years ago
parent
commit
de5a3c118a
1 changed files with 4 additions and 1 deletions
  1. 4 1
      Source/Urho3D/Scene/Node.cpp

+ 4 - 1
Source/Urho3D/Scene/Node.cpp

@@ -2084,9 +2084,12 @@ void Node::UpdateWorldTransform() const
 
 
 void Node::RemoveChild(Vector<SharedPtr<Node> >::Iterator i)
 void Node::RemoveChild(Vector<SharedPtr<Node> >::Iterator i)
 {
 {
-    // Send change event. Do not send when already being destroyed
+    // Keep a shared pointer to the child about to be removed, to make sure the erase from container completes first. Otherwise
+    // it would be possible that other child nodes get removed as part of the node's components' cleanup, causing a re-entrant
+    // erase and a crash
     SharedPtr<Node> child(*i);
     SharedPtr<Node> child(*i);
 
 
+    // Send change event. Do not send when this node is already being destroyed
     if (Refs() > 0 && scene_)
     if (Refs() > 0 && scene_)
     {
     {
         using namespace NodeRemoved;
         using namespace NodeRemoved;