fix(profile): avoid freeing nodes during their own signal

Defer frame selection and use queued deletion when rebuilding frame cards, avatars, Guest Book cards, and legend chips. Adds a regression check that presses a frame card and verifies the grid stays stable.
This commit is contained in:
Ratdoku Builder committed 2026-12-02 22:48:08 -06:00
1 parent 3c2ead0be1
commit 48c14864a4
5 files changed
+41 -12

No files matched your search

+1 -1
View File
@@ -266,7 +266,7 @@ func start_daily(index: int, key: String) -> void:
func _refresh_legend() -> void:
for child in legend_row.get_children():
child.free()
child.queue_free()
legend_chips.clear()
if board.region_rats.is_empty():
return
+2 -2
View File
@@ -99,7 +99,7 @@ func _build_crumb_frame() -> void:
if crumb_frame_id == selected and crumb_frame_holder.get_child_count() > 0:
return
for child in crumb_frame_holder.get_children():
child.free()
child.queue_free()
var frame := Frames.frame_panel(selected, 56)
var portrait := TextureRect.new()
portrait.custom_minimum_size = Vector2(44, 44)
@@ -145,7 +145,7 @@ func refresh() -> void:
return
_build_crumb_frame()
for child in grid.get_children():
child.free()
child.queue_free()
var guests := Guests.all()
var unlocked := SaveGame.unlocked_count(guests)
+1 -1
View File
@@ -166,7 +166,7 @@ func _refresh_avatar() -> void:
if avatar_frame_id == SaveGame.selected_frame():
return
for child in avatar_holder.get_children():
child.free()
child.queue_free()
_build_avatar()
+8 -2
View File
@@ -104,7 +104,7 @@ func _build_portrait() -> void:
if portrait_frame_id == selected and portrait_holder.get_child_count() > 0:
return
for child in portrait_holder.get_children():
child.free()
child.queue_free()
var frame := Frames.frame_panel(selected, 118)
var head := TextureRect.new()
head.texture = load("res://art/crumb_head.png")
@@ -119,7 +119,7 @@ func _build_portrait() -> void:
func _build_frames() -> void:
for child in frame_grid.get_children():
child.free()
child.queue_free()
var selected := SaveGame.selected_frame()
for frame in Frames.all():
@@ -183,6 +183,12 @@ func _on_frame_pressed(id: String, unlocked: bool) -> void:
status_label.text = "Locked: %s." % Frames.requirement_text(id)
status_label.add_theme_color_override("font_color", Palette.RED)
return
# Never rebuild the card grid while the card's own `pressed` signal is
# still on the stack; Godot locks the emitting node during the call.
call_deferred("_apply_frame", id)
func _apply_frame(id: String) -> void:
SaveGame.select_frame(id)
status_label.text = "Now wearing %s." % str(Frames.by_id(id).get("name", id))
status_label.add_theme_color_override("font_color", Palette.MUTED)
+29 -6
View File
@@ -4,6 +4,7 @@ extends SceneTree
## <godot> --headless --path . --script res://tools/ui_test.gd
var failures := 0
var frames = null
func _init() -> void:
@@ -33,6 +34,13 @@ func _run() -> void:
quit(1)
return
# Resolve at runtime so Frames.gd does not compile before autoloads exist.
frames = load("res://scripts/Frames.gd")
_check(frames != null, "Frames script missing")
if frames == null:
quit(1)
return
_test_save_defaults(save)
save.reset_progress()
await _test_daily_and_frames(save, main)
@@ -141,18 +149,18 @@ func _test_daily_and_frames(save, main) -> void:
save.save_game()
save.reset_progress()
_check(Frames.is_unlocked("plain"), "plain frame should always be available")
_check(not Frames.is_unlocked("paper"), "Paper should need rooms")
_check(frames.is_unlocked("plain"), "plain frame should always be available")
_check(not frames.is_unlocked("paper"), "Paper should need rooms")
for i in range(5):
save.data["completed_rooms"].append("room-%02d" % i)
save.save_game()
_check(Frames.is_unlocked("paper"), "five rooms should unlock Paper")
_check(not Frames.is_unlocked("bell"), "Bellhop should still be locked")
_check(frames.is_unlocked("paper"), "five rooms should unlock Paper")
_check(not frames.is_unlocked("bell"), "Bellhop should still be locked")
var stats: Dictionary = save.daily_data()
stats["best_streak"] = 3
save.data["daily"] = stats
save.save_game()
_check(Frames.is_unlocked("regular"), "a 3-day best streak should unlock Regular")
_check(frames.is_unlocked("regular"), "a 3-day best streak should unlock Regular")
save.select_frame("regular")
save.load_game()
_check(save.selected_frame() == "regular", "frame selection should persist")
@@ -162,13 +170,28 @@ func _test_daily_and_frames(save, main) -> void:
_check(main.profile != null, "Profile screen missing")
if main.profile != null:
_check(
main.profile.frame_grid.get_child_count() == Frames.all().size(),
main.profile.frame_grid.get_child_count() == frames.all().size(),
"Profile should show every frame"
)
_check(
main.profile.frame_grid.get_child(0).mouse_filter == Control.MOUSE_FILTER_PASS,
"frame cards should pass swipes"
)
# Regression: pressing a card must not free that card while its
# `pressed` signal is still on the stack.
var regular_index := -1
for i in frames.all().size():
if str(frames.all()[i].get("id", "")) == "regular":
regular_index = i
if regular_index >= 0:
main.profile.frame_grid.get_child(regular_index).pressed.emit()
await process_frame
await process_frame
_check(save.selected_frame() == "regular", "frame press should select the frame")
_check(
main.profile.frame_grid.get_child_count() == frames.all().size(),
"frame grid should stay stable after selection"
)
main.show_screen("home")
main.home.daily_pressed.emit()
await process_frame