summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Sauermann <6299227+Sauermann@users.noreply.github.com>2023-06-24 22:15:50 +0200
committerMarkus Sauermann <6299227+Sauermann@users.noreply.github.com>2023-06-25 22:35:38 +0200
commit31fab43b8bde2d6b01f034c8c976756d5211abff (patch)
treeb4a53aced4b976e4b40d8b2b51f9a631a461bac3
parent030c1a950e8cee19e72104b4fb79caba17a2d678 (diff)
downloadredot-engine-31fab43b8bde2d6b01f034c8c976756d5211abff.tar.gz
Fix scene load crash related to `_ready`
The iterator might get invalidated during `_ready`-user-code. Prevent this by disallowing set_name during iterator-operations.
-rw-r--r--scene/main/node.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index a21866610c..515bd60cca 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -595,9 +595,11 @@ void Node::_propagate_pause_notification(bool p_enable) {
notification(NOTIFICATION_UNPAUSED);
}
+ data.blocked++;
for (KeyValue<StringName, Node *> &K : data.children) {
K.value->_propagate_pause_notification(p_enable);
}
+ data.blocked--;
}
Node::ProcessMode Node::get_process_mode() const {
@@ -615,12 +617,14 @@ void Node::_propagate_process_owner(Node *p_owner, int p_pause_notification, int
notification(p_enabled_notification);
}
+ data.blocked++;
for (KeyValue<StringName, Node *> &K : data.children) {
Node *c = K.value;
if (c->data.process_mode == PROCESS_MODE_INHERIT) {
c->_propagate_process_owner(p_owner, p_pause_notification, p_enabled_notification);
}
}
+ data.blocked--;
}
void Node::set_multiplayer_authority(int p_peer_id, bool p_recursive) {
@@ -1132,7 +1136,8 @@ void Node::_set_name_nocheck(const StringName &p_name) {
}
void Node::set_name(const String &p_name) {
- ERR_FAIL_COND_MSG(data.inside_tree && !Thread::is_main_thread(), "Changing the name to nodes inside the SceneTree is only allowed from the main thread. Use call_deferred(\"set_name\",new_name).");
+ ERR_FAIL_COND_MSG(data.inside_tree && !Thread::is_main_thread(), "Changing the name to nodes inside the SceneTree is only allowed from the main thread. Use `set_name.call_deferred(new_name)`.");
+ ERR_FAIL_COND_MSG(data.parent && data.parent->data.blocked > 0, "Parent node is busy setting up children, `set_name(new_name)` failed. Consider using `set_name.call_deferred(new_name)` instead.");
String name = p_name.validate_node_name();
ERR_FAIL_COND(name.is_empty());