Fix use-after-free crash on second round start #83

Merged
cammymoop merged 1 commit from feature/fix-round-restart-crash into master 2026-03-05 15:09:41 -06:00
Collaborator

Summary

  • start_round() calls queue_free() on old level children then immediately add_child() the new level. Queue-freed nodes stay in their groups until end-of-frame, so new BallSystem._find_player() and WaveSpawner._ready() could pick up the old (about-to-be-freed) instances.
  • Fixed by filtering group lookups with is_queued_for_deletion() in both places.
  • Added is_instance_valid(ball_system) guard in WaveSpawner._spawn_pending() as a safety net.

Test plan

  • gdlint passes
  • Headless run exits cleanly
  • Start a second round — no crash on ball spawn or player melee
## Summary - `start_round()` calls `queue_free()` on old level children then immediately `add_child()` the new level. Queue-freed nodes stay in their groups until end-of-frame, so new `BallSystem._find_player()` and `WaveSpawner._ready()` could pick up the old (about-to-be-freed) instances. - Fixed by filtering group lookups with `is_queued_for_deletion()` in both places. - Added `is_instance_valid(ball_system)` guard in `WaveSpawner._spawn_pending()` as a safety net. ## Test plan - [x] gdlint passes - [x] Headless run exits cleanly - [ ] Start a second round — no crash on ball spawn or player melee
start_round() calls queue_free() on the old level then immediately
add_child() on the new level. queue_freed nodes stay in their groups
until end of frame, so the new BallSystem and WaveSpawner could pick
up the old (soon-to-be-freed) Player/BallSystem from group lookups.

- BallSystem._find_player(): skip nodes where is_queued_for_deletion()
- WaveSpawner._ready(): same filter for the ball_system group lookup
- WaveSpawner._spawn_pending(): guard with is_instance_valid() in case
  a tween fires during level teardown

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
cammymoop merged commit 846a424461 into master 2026-03-05 15:09:41 -06:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cammymoop/semi-vibed-game!83
No description provided.