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:
1 parent
3c2ead0be1
commit
48c14864a4
5 files changed
+41
-12
No files matched your search
+1
-1
@@ -266,7 +266,7 @@ func start_daily(index: int, key: String) -> void:
|
|||||||
|
|
||||||
func _refresh_legend() -> void:
|
func _refresh_legend() -> void:
|
||||||
for child in legend_row.get_children():
|
for child in legend_row.get_children():
|
||||||
child.free()
|
child.queue_free()
|
||||||
legend_chips.clear()
|
legend_chips.clear()
|
||||||
if board.region_rats.is_empty():
|
if board.region_rats.is_empty():
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ func _build_crumb_frame() -> void:
|
|||||||
if crumb_frame_id == selected and crumb_frame_holder.get_child_count() > 0:
|
if crumb_frame_id == selected and crumb_frame_holder.get_child_count() > 0:
|
||||||
return
|
return
|
||||||
for child in crumb_frame_holder.get_children():
|
for child in crumb_frame_holder.get_children():
|
||||||
child.free()
|
child.queue_free()
|
||||||
var frame := Frames.frame_panel(selected, 56)
|
var frame := Frames.frame_panel(selected, 56)
|
||||||
var portrait := TextureRect.new()
|
var portrait := TextureRect.new()
|
||||||
portrait.custom_minimum_size = Vector2(44, 44)
|
portrait.custom_minimum_size = Vector2(44, 44)
|
||||||
@@ -145,7 +145,7 @@ func refresh() -> void:
|
|||||||
return
|
return
|
||||||
_build_crumb_frame()
|
_build_crumb_frame()
|
||||||
for child in grid.get_children():
|
for child in grid.get_children():
|
||||||
child.free()
|
child.queue_free()
|
||||||
|
|
||||||
var guests := Guests.all()
|
var guests := Guests.all()
|
||||||
var unlocked := SaveGame.unlocked_count(guests)
|
var unlocked := SaveGame.unlocked_count(guests)
|
||||||
|
|||||||
+1
-1
@@ -166,7 +166,7 @@ func _refresh_avatar() -> void:
|
|||||||
if avatar_frame_id == SaveGame.selected_frame():
|
if avatar_frame_id == SaveGame.selected_frame():
|
||||||
return
|
return
|
||||||
for child in avatar_holder.get_children():
|
for child in avatar_holder.get_children():
|
||||||
child.free()
|
child.queue_free()
|
||||||
_build_avatar()
|
_build_avatar()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -104,7 +104,7 @@ func _build_portrait() -> void:
|
|||||||
if portrait_frame_id == selected and portrait_holder.get_child_count() > 0:
|
if portrait_frame_id == selected and portrait_holder.get_child_count() > 0:
|
||||||
return
|
return
|
||||||
for child in portrait_holder.get_children():
|
for child in portrait_holder.get_children():
|
||||||
child.free()
|
child.queue_free()
|
||||||
var frame := Frames.frame_panel(selected, 118)
|
var frame := Frames.frame_panel(selected, 118)
|
||||||
var head := TextureRect.new()
|
var head := TextureRect.new()
|
||||||
head.texture = load("res://art/crumb_head.png")
|
head.texture = load("res://art/crumb_head.png")
|
||||||
@@ -119,7 +119,7 @@ func _build_portrait() -> void:
|
|||||||
|
|
||||||
func _build_frames() -> void:
|
func _build_frames() -> void:
|
||||||
for child in frame_grid.get_children():
|
for child in frame_grid.get_children():
|
||||||
child.free()
|
child.queue_free()
|
||||||
|
|
||||||
var selected := SaveGame.selected_frame()
|
var selected := SaveGame.selected_frame()
|
||||||
for frame in Frames.all():
|
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.text = "Locked: %s." % Frames.requirement_text(id)
|
||||||
status_label.add_theme_color_override("font_color", Palette.RED)
|
status_label.add_theme_color_override("font_color", Palette.RED)
|
||||||
return
|
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)
|
SaveGame.select_frame(id)
|
||||||
status_label.text = "Now wearing %s." % str(Frames.by_id(id).get("name", 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)
|
status_label.add_theme_color_override("font_color", Palette.MUTED)
|
||||||
|
|||||||
+29
-6
@@ -4,6 +4,7 @@ extends SceneTree
|
|||||||
## <godot> --headless --path . --script res://tools/ui_test.gd
|
## <godot> --headless --path . --script res://tools/ui_test.gd
|
||||||
|
|
||||||
var failures := 0
|
var failures := 0
|
||||||
|
var frames = null
|
||||||
|
|
||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
@@ -33,6 +34,13 @@ func _run() -> void:
|
|||||||
quit(1)
|
quit(1)
|
||||||
return
|
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)
|
_test_save_defaults(save)
|
||||||
save.reset_progress()
|
save.reset_progress()
|
||||||
await _test_daily_and_frames(save, main)
|
await _test_daily_and_frames(save, main)
|
||||||
@@ -141,18 +149,18 @@ func _test_daily_and_frames(save, main) -> void:
|
|||||||
save.save_game()
|
save.save_game()
|
||||||
|
|
||||||
save.reset_progress()
|
save.reset_progress()
|
||||||
_check(Frames.is_unlocked("plain"), "plain frame should always be available")
|
_check(frames.is_unlocked("plain"), "plain frame should always be available")
|
||||||
_check(not Frames.is_unlocked("paper"), "Paper should need rooms")
|
_check(not frames.is_unlocked("paper"), "Paper should need rooms")
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
save.data["completed_rooms"].append("room-%02d" % i)
|
save.data["completed_rooms"].append("room-%02d" % i)
|
||||||
save.save_game()
|
save.save_game()
|
||||||
_check(Frames.is_unlocked("paper"), "five rooms should unlock Paper")
|
_check(frames.is_unlocked("paper"), "five rooms should unlock Paper")
|
||||||
_check(not Frames.is_unlocked("bell"), "Bellhop should still be locked")
|
_check(not frames.is_unlocked("bell"), "Bellhop should still be locked")
|
||||||
var stats: Dictionary = save.daily_data()
|
var stats: Dictionary = save.daily_data()
|
||||||
stats["best_streak"] = 3
|
stats["best_streak"] = 3
|
||||||
save.data["daily"] = stats
|
save.data["daily"] = stats
|
||||||
save.save_game()
|
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.select_frame("regular")
|
||||||
save.load_game()
|
save.load_game()
|
||||||
_check(save.selected_frame() == "regular", "frame selection should persist")
|
_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")
|
_check(main.profile != null, "Profile screen missing")
|
||||||
if main.profile != null:
|
if main.profile != null:
|
||||||
_check(
|
_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"
|
"Profile should show every frame"
|
||||||
)
|
)
|
||||||
_check(
|
_check(
|
||||||
main.profile.frame_grid.get_child(0).mouse_filter == Control.MOUSE_FILTER_PASS,
|
main.profile.frame_grid.get_child(0).mouse_filter == Control.MOUSE_FILTER_PASS,
|
||||||
"frame cards should pass swipes"
|
"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.show_screen("home")
|
||||||
main.home.daily_pressed.emit()
|
main.home.daily_pressed.emit()
|
||||||
await process_frame
|
await process_frame
|
||||||
|
|||||||
Reference in new issue
Block a user