diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-21 11:28:02 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-21 11:28:02 +0100 |
commit | 7b622ce6e8a40508dbfccb21380e5f0b2dd45fac (patch) | |
tree | 633abb4f920e5a365b8b781e5d6cbc91734b92f9 /scene/main/node.cpp | |
parent | d45af488c47a1ed1812e5b6c5c01beee4890e250 (diff) | |
parent | 398e73c689e8506933a066c6a8045a50f58d0c04 (diff) | |
download | redot-engine-7b622ce6e8a40508dbfccb21380e5f0b2dd45fac.tar.gz |
Merge pull request #71021 from reduz/prevent-physics-callback-removal
Error when removing a physics node during a physics callback
Diffstat (limited to 'scene/main/node.cpp')
-rw-r--r-- | scene/main/node.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp index eb57ccfef1..def91c424c 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -279,7 +279,10 @@ void Node::_propagate_exit_tree() { //block while removing children #ifdef DEBUG_ENABLED - SceneDebugger::remove_from_cache(data.scene_file_path, this); + if (!data.scene_file_path.is_empty()) { + // Only remove if file path is set (optimization). + SceneDebugger::remove_from_cache(data.scene_file_path, this); + } #endif data.blocked++; @@ -305,7 +308,6 @@ void Node::_propagate_exit_tree() { } // exit groups - for (KeyValue<StringName, GroupData> &E : data.grouped) { data.tree->remove_from_group(E.key, this); E.value.group = nullptr; @@ -1166,7 +1168,7 @@ void Node::add_sibling(Node *p_sibling, bool p_force_readable_name) { void Node::remove_child(Node *p_child) { ERR_FAIL_NULL(p_child); - ERR_FAIL_COND_MSG(data.blocked > 0, "Parent node is busy setting up children, `remove_child()` failed. Consider using `remove_child.call_deferred(child)` instead."); + ERR_FAIL_COND_MSG(data.blocked > 0, "Parent node is busy adding/removing children, `remove_child()` can't be called at this time. Consider using `remove_child.call_deferred(child)` instead."); int child_count = data.children.size(); Node **children = data.children.ptrw(); @@ -1197,11 +1199,13 @@ void Node::remove_child(Node *p_child) { data.internal_children_back--; } + data.blocked++; p_child->_set_tree(nullptr); //} remove_child_notify(p_child); p_child->notification(NOTIFICATION_UNPARENTED); + data.blocked--; data.children.remove_at(idx); |