diff options
Diffstat (limited to 'scene/main/node.cpp')
-rw-r--r-- | scene/main/node.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 3715c06a33..8d5133311a 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -645,7 +645,8 @@ int Node::get_multiplayer_authority() const { bool Node::is_multiplayer_authority() const { ERR_FAIL_COND_V(!is_inside_tree(), false); - return get_multiplayer()->get_unique_id() == data.multiplayer_authority; + Ref<MultiplayerAPI> api = get_multiplayer(); + return api.is_valid() && (api->get_unique_id() == data.multiplayer_authority); } /***** RPC CONFIG ********/ @@ -724,7 +725,12 @@ Error Node::_rpc_id_bind(const Variant **p_args, int p_argcount, Callable::CallE Error Node::rpcp(int p_peer_id, const StringName &p_method, const Variant **p_arg, int p_argcount) { ERR_FAIL_COND_V(!is_inside_tree(), ERR_UNCONFIGURED); - return get_multiplayer()->rpcp(this, p_peer_id, p_method, p_arg, p_argcount); + + Ref<MultiplayerAPI> api = get_multiplayer(); + if (api.is_null()) { + return ERR_UNCONFIGURED; + } + return api->rpcp(this, p_peer_id, p_method, p_arg, p_argcount); } Ref<MultiplayerAPI> Node::get_multiplayer() const { @@ -1139,7 +1145,6 @@ 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 `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()); @@ -1151,9 +1156,9 @@ void Node::set_name(const String &p_name) { data.name = name; if (data.parent) { - data.parent->data.children.erase(old_name); data.parent->_validate_child_name(this, true); - data.parent->data.children.insert(data.name, this); + bool success = data.parent->data.children.replace_key(old_name, data.name); + ERR_FAIL_COND_MSG(!success, "Renaming child in hashtable failed, this is a bug."); } if (data.unique_name_in_owner && data.owner) { @@ -1906,7 +1911,7 @@ void Node::set_owner(Node *p_owner) { check = check->data.parent; } - ERR_FAIL_COND(!owner_valid); + ERR_FAIL_COND_MSG(!owner_valid, "Invalid owner. Owner must be an ancestor in the tree."); _set_owner_nocheck(p_owner); |