Godot Version
4.3
Question
I'm making a multiplayer game but the client crashes when the server disconnects manually, and the client doesn't have any stacktrace to track the error, i'll add some of the responsible code
# This is called on pressing back to menu
func _go_to_select_menu() -> void:
var id := multiplayer.get_unique_id()
multiplayer_handler.disconnect_peer(id)
NetworkingLogger.push_log("Peer ID: %s disconnected" % id)
get_tree().change_scene_to_packed(SELECT_MENU)
## Closes multiplayer_peer safely
func close_peer():
NetworkingLogger.push_log("Peer ID: %s closed" % multiplayer.get_unique_id())
multiplayer.multiplayer_peer.close()
# For some reason this dodges a weird bug when server disconnects
# Reference: https://github.com/godotengine/godot/issues/77723#issuecomment-1830689802
multiplayer.multiplayer_peer = OfflineMultiplayerPeer.new()
## Closes peer and despawns player
func disconnect_peer(id):
close_peer()
new_game.despawn_player(id)