2
0
Эх сурвалжийг харах

Prevent crash when accessing `Node` Multiplayer from thread

(cherry picked from commit 7bd3a3a5e539d22302ce388f6bcae64f2e78f7c8)
Ninni Pipping 2 жил өмнө
parent
commit
f54cbe6b76

+ 8 - 2
scene/main/node.cpp

@@ -645,7 +645,8 @@ int Node::get_multiplayer_authority() const {
 bool Node::is_multiplayer_authority() const {
 bool Node::is_multiplayer_authority() const {
 	ERR_FAIL_COND_V(!is_inside_tree(), false);
 	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 ********/
 /***** 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) {
 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);
 	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 {
 Ref<MultiplayerAPI> Node::get_multiplayer() const {