Fix ESC-crashes-the-game, avatar facing backward, invisible build stamp
checkpoint / checkpoint (push) Successful in 1m47s

ESC: player.gd changed scene directly while game.gd._exit_tree closed the
socket, which re-fired server_disconnected -> _on_server_lost ran mid-
teardown (add_child on an exiting node, await on a null get_tree(), a
second change_scene_to_file). Moved ESC to game.gd as one ordered path:
_leave_world() sets a _leaving guard, disconnects the _on_server_lost
handlers before closing the connection, then changes scene. _on_server_lost
and _exit_tree now respect the guard. Verified headless: ESC -> world_list,
no errors; 2p multiplayer still connects.

Avatar faced +Z but a Godot node's forward is -Z, so walking forward
showed the character its own face. Rebuilt the placeholder facing -Z (face
plates, eyes, jaw, toes, and front-mounted attachments all moved to
negative Z; backpack/ponytail to +Z). The procedural walk was already
written for -Z forward, so it's unchanged.

Build stamp was there but tiny/low-contrast bottom-left -- bumped to 20px
opaque yellow with a heavy outline, moved to the top-left strip.

limb_animator: guard _process with is_instance_valid(_skel) so a frame
landing during avatar teardown can't touch a freed skeleton.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015jtxAiu5dAW4WxCNdGkrkJ
This commit is contained in:
2026-09-06 14:24:45 +00:00
parent 3fb45f0ef2
commit eb4da62f99
11 changed files with 71 additions and 39 deletions
+51 -18
View File
@@ -22,6 +22,7 @@ const CORRECTION_THRESHOLD := 0.6
var _net: NetworkClient = null
var _networked := false
var _leaving := false # a scene change is already in flight
var _aligned := false # snapped to the server spawn yet?
var _remotes: Dictionary = {} # peer_id -> Node3D
var _remote_prev: Dictionary = {} # peer_id -> Vector3 (last snapshot position)
@@ -34,6 +35,37 @@ func _ready() -> void:
_setup_networked()
func _unhandled_input(event: InputEvent) -> void:
# ESC leaves the world back to the browser. Handled here (the scene root
# that owns the connection) rather than in player.gd so the teardown is
# a single ordered path -- doing it from two places raced _on_server_lost
# against the scene change and looked like a crash.
if event.is_action_pressed("ui_cancel"):
get_viewport().set_input_as_handled()
_leave_world()
func _leave_world() -> void:
if _leaving:
return
_leaving = true
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
_teardown_net()
Session.clear()
get_tree().change_scene_to_file("res://scenes/world_list.tscn")
## Close the ENet connection and stop it from calling us back mid-teardown.
func _teardown_net() -> void:
if _net == null or not is_instance_valid(_net):
return
if _net.server_disconnected.is_connected(_on_server_lost):
_net.server_disconnected.disconnect(_on_server_lost)
if _net.connection_failed.is_connected(_on_server_lost):
_net.connection_failed.disconnect(_on_server_lost)
_net.disconnect_from_server()
static func _build_label() -> String:
var f := FileAccess.open("res://assets/build_info.json", FileAccess.READ)
@@ -51,30 +83,28 @@ func _show_build_stamp() -> void:
add_child(layer)
var lbl := Label.new()
lbl.text = "build %s" % _build_label()
lbl.add_theme_color_override("font_color", Color(1, 1, 0.45))
lbl.add_theme_color_override("font_outline_color", Color(0, 0, 0, 0.85))
lbl.add_theme_constant_override("outline_size", 4)
lbl.add_theme_font_size_override("font_size", 14)
# Anchor a full-width strip to the bottom of the screen and left-align the
# text in it. (A bare preset + .position on a zero-size Label collapses the
# rect to negative width and nothing draws -- which is why this never showed.)
lbl.set_anchors_preset(Control.PRESET_BOTTOM_WIDE)
lbl.add_theme_color_override("font_color", Color(1, 1, 0.35))
lbl.add_theme_color_override("font_outline_color", Color(0, 0, 0, 1))
lbl.add_theme_constant_override("outline_size", 6)
lbl.add_theme_font_size_override("font_size", 20)
# Full-width strip pinned to the TOP-left. (A bare preset + .position on a
# zero-size Label collapses the rect to negative width and nothing draws --
# which is why this never showed; explicit offsets fix it.)
lbl.set_anchors_preset(Control.PRESET_TOP_WIDE)
lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
lbl.vertical_alignment = VERTICAL_ALIGNMENT_BOTTOM
lbl.offset_left = 8
lbl.offset_right = -8
lbl.offset_top = -30
lbl.offset_bottom = -6
lbl.offset_left = 12
lbl.offset_right = -12
lbl.offset_top = 8
lbl.offset_bottom = 40
lbl.mouse_filter = Control.MOUSE_FILTER_IGNORE
layer.add_child(lbl)
func _exit_tree() -> void:
# Leaving the world -- close the ENet connection cleanly so the server
# fires peer_disconnected and removes our player (otherwise everyone else
# keeps seeing a frozen "ghost" of us).
if _net != null and is_instance_valid(_net):
_net.disconnect_from_server()
# Backstop for any exit path that didn't go through _leave_world (e.g. the
# app quitting): close the ENet connection so the server fires
# peer_disconnected and drops our player instead of leaving a ghost.
_teardown_net()
func _setup_networked() -> void:
@@ -205,6 +235,9 @@ func _all_mesh_instances(node: Node, out: Array = []) -> Array:
func _on_server_lost() -> void:
if _leaving:
return
_leaving = true
_networked = false
_show_status("Disconnected from the server. Returning to worlds…")
await get_tree().create_timer(1.5).timeout