From 1f7846abf8e2c3ec132426ef4d9c785297614244 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Tue, 15 Jan 2019 10:35:26 +0100 Subject: Fix MultiplayerAPI initialization, clear. rpc_sender_id is now correctly initialized to 0 so get_rpc_sender_id() work reliably even if called before receiving any RPC. root_node is initialized to NULL (fix crashes when incorrectly using the MultiplayerAPI). clear function now resets the packet cache size to free more memory when not running. --- core/io/multiplayer_api.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'core') diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index 30c5bfcaa7..9a2dddbb82 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -122,6 +122,7 @@ void MultiplayerAPI::clear() { connected_peers.clear(); path_get_cache.clear(); path_send_cache.clear(); + packet_cache.clear(); last_send_cache_id = 1; } @@ -857,6 +858,8 @@ void MultiplayerAPI::_bind_methods() { } MultiplayerAPI::MultiplayerAPI() { + rpc_sender_id = 0; + root_node = NULL; clear(); } -- cgit v1.2.3 From 60d235622d13b8126001e61da096ca48244c2733 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Tue, 15 Jan 2019 11:14:51 +0100 Subject: Don't reset MultiplayerAPI when setting same peer. A GDScript call to: `multiplayer.network_peer.some_prop = true` seems to transalte to: ``` var temp = multiplayer.network_peer temp.some_prop = true multiplayer.network_peer = temp ``` Which caused the MultiplayerAPI to be resetted. The call to set_network_peer is now ignored if the peer that's beeing set is the same as the currently set one. --- core/io/multiplayer_api.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core') diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index 9a2dddbb82..7680d47620 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -132,6 +132,8 @@ void MultiplayerAPI::set_root_node(Node *p_node) { void MultiplayerAPI::set_network_peer(const Ref &p_peer) { + if (p_peer == network_peer) return; // Nothing to do + if (network_peer.is_valid()) { network_peer->disconnect("peer_connected", this, "_add_peer"); network_peer->disconnect("peer_disconnected", this, "_del_peer"); -- cgit v1.2.3