🐛 Fix crashes when leaving Multiplayer mode

This commit is contained in:
Squinty 2024-04-24 21:26:14 +00:00
parent e02f52be49
commit f9c5a2218e
4 changed files with 12 additions and 10 deletions

View file

@ -53,6 +53,7 @@ enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD }
@onready var spring_arm_height : float = $Smoothing/SpringArm3D.position.y
@onready var _original_weapon_transform : Transform3D = weapon.transform
@onready var flag_carry_attachment : Node3D = $Smoothing/SpringArm3D/FlagCarryAttachment
@onready var tp_player : Vanguard = $Smoothing/ThirdPerson/PlayerMesh
@onready var _game_settings : Settings = get_node("/root/GlobalSettings")
signal died(player : Player, killer_id : int)
@ -154,7 +155,7 @@ func _process(_delta : float) -> void:
else:
iff.show()
if not _is_pawn():
$Smoothing/ThirdPerson/PlayerMesh.global_transform.basis = Basis.from_euler(Vector3(0.0, input.camera_rotation.x + PI, 0.0))
tp_player.global_transform.basis = Basis.from_euler(Vector3(0.0, input.camera_rotation.x + PI, 0.0))
elif not %Inventory/SpaceGun/Mesh/AnimationPlayer.is_playing():
%Inventory/SpaceGun/Mesh/AnimationPlayer.play("idle")
%SpringArm3D.global_transform.basis = Basis.from_euler(Vector3(input.camera_rotation.y, input.camera_rotation.x, 0.0))
@ -211,8 +212,6 @@ func _update_third_person_animations() -> void:
if _is_pawn():
return
var tp_player : Vanguard = $Smoothing/ThirdPerson/PlayerMesh
if _is_player_dead():
tp_player.set_ground_state(Vanguard.GroundState.GROUND_STATE_DEAD)
return
@ -241,3 +240,7 @@ func respawn(location : Vector3) -> void:
linear_velocity = Vector3()
health_component.heal_full()
position = location
func _exit_tree() -> void:
player_state = PlayerState.PLAYER_DEAD
flag_carry_component.drop()

View file

@ -23,10 +23,6 @@ class ScoreboardEntry:
var nickname_label : Label = Label.new()
var kills_label : Label = Label.new()
var score_label : Label = Label.new()
func free() -> void:
nickname_label.queue_free()
kills_label.queue_free()
super.free()
func _unhandled_input(event : InputEvent) -> void:
if event.is_action_pressed("scoreboard"):
@ -76,7 +72,9 @@ func _update_scoreboard_entry(player_id : int, nickname : String, kills : int, s
@rpc("authority", "call_local", "reliable")
func _remove_scoreboard_entry(player_id : int) -> void:
var entry : ScoreboardEntry = _entries[player_id]
entry.free()
entry.nickname_label.queue_free()
entry.kills_label.queue_free()
entry.score_label.queue_free()
_entries.erase(player_id)
func _update_scoreboard_entry_ui(player_id : int) -> void:

View file

@ -45,7 +45,7 @@ func _unhandled_input(event : InputEvent) -> void:
else:
# show boot menu
$BootMenu.show()
# switch window mode
if event.is_action_pressed(\"window_mode\"):
if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN:

View file

@ -93,7 +93,7 @@ func remove_player(peer_id : int) -> void:
if players.has_node(node_name):
var player : Player = players.get_node(node_name)
scoreboard.remove_player(player)
player.die(-1)
player.died.disconnect(_on_player_died)
player.queue_free()
print("Peer `%s` disconnected" % node_name)
@ -130,3 +130,4 @@ func _on_flag_carrier_scoring_timer_timeout() -> void:
func _exit_tree() -> void:
if is_multiplayer_authority():
multiplayer.peer_disconnected.disconnect(remove_player)
multiplayer.multiplayer_peer = null