From 7561e176e8f68770c70c7b119bf970bd53ffa3ec Mon Sep 17 00:00:00 2001 From: Markus Sauermann <6299227+Sauermann@users.noreply.github.com> Date: Thu, 8 Jun 2023 22:49:40 +0200 Subject: [PATCH] Fix parent inconsistency in `Node::remove_child` `NOTIFICATION_CHILD_ORDER_CHANGED` could be triggered, while there was an inconsistent state: - parent node no longer had child listed as child - child node still had parent node listed as parent Bring these two in sync, before emitting the notification. --- scene/main/node.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 094c3f0c941..a9fff264e4a 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1439,12 +1439,12 @@ void Node::remove_child(Node *p_child) { bool success = data.children.erase(p_child->data.name); ERR_FAIL_COND_MSG(!success, "Children name does not match parent name in hashtable, this is a bug."); - notification(NOTIFICATION_CHILD_ORDER_CHANGED); - emit_signal(SNAME("child_order_changed")); - p_child->data.parent = nullptr; p_child->data.index = -1; + notification(NOTIFICATION_CHILD_ORDER_CHANGED); + emit_signal(SNAME("child_order_changed")); + if (data.inside_tree) { p_child->_propagate_after_exit_tree(); }