Skip to content

Do not run onDestroyed callbacks while tearing down all entities (#1465) - #2920

Open
dj803 wants to merge 1 commit into
daid:masterfrom
dj803:drowa/ee1465-teardown
Open

dj803 wants to merge 1 commit into
daid:masterfrom
dj803:drowa/ee1465-teardown

Conversation

@dj803

@dj803 dj803 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #1465.

GameGlobalInfo::reset() calls sp::ecs::Entity::destroyAllEntities(). Each destroy runs the entity's Lua onDestroyed callback. A callback that creates a ship during teardown gets a freed entity slot, so the new ship survives into the next scenario. As agreed in the issue thread, callbacks should not run while everything is being destroyed.

Change:

  • OnDestroySystem::destroyAllEntities() sets a flag; destroyCallback returns early while it is set; it then calls Entity::destroyAllEntities().
  • GameGlobalInfo::reset() and TutorialGame::finish() (repeated tutorial) call it instead of Entity::destroyAllEntities().
  • 4 files, +19/-2. Normal single-entity destruction is unchanged.

Note: the line in reset() is also adjacent to the hunk in #2891; trivial conflict if both land.

Test

Scenario: phase 1 makes 3 stations + a ship whose onDestroyed spawns a ship called LEAK, then calls setScenario on itself; phase 2 counts objects and LEAK ships. Variant B has the callback spawn 2 ships and logs each callback run. Windows build, headless, one run each.

Scenario Build Callbacks run Objects after reset LEAK ships
A (callback spawns 1) master (before) 1 1 1
A this PR (after) 0 0 0
B (callback spawns 2) master (before) 1 2 2
B this PR (after) 0 0 0

(Callback count: B logs "EE1465B spawn" per callback run: 1 before, 0 after. A: leak count equals runs.)

Stock scenarios (all 40 scenario_*.lua, Windows, headless): each run 10 s, then setScenario to a probe that counts objects. 35 completed the switch on both builds; same 5 did not on both (harness limits, not the change). All 35 end with 0 objects on this PR. On master, scenario_59_border leaves 37 objects after the switch (this PR: 0), and scenario_30_brokenglass ("attempt to index a nil value") and scenario_79_kessler ("Attempted to set victory faction to Ghosts...") log errors raised during teardown (this PR: none). Pre-switch object counts vary run to run (unseeded).

Not tested

  • Multiplayer / connected clients during a scenario switch.
  • The repeated-tutorial path (TutorialGame::finish): compiled only, not run.
  • Linux / macOS builds; upstream CI not replicated locally.
  • Scenarios 08, 22, 23, 24 and 56 could not be run through the switch harness on either build (wrapper/setup limits), so they are not covered. Scenarios were switched away after 10 s, not played.
  • Scripts that relied on an onDestroyed callback firing during scenario switch (behaviour change by design).
  • The "teardown loop never ends" case from the issue text could not be reproduced (variant B ended normally); only the leaked-entity symptom is confirmed.
  • The tests above were first run with a locally patched SeriousProton, then re-run against upstream SeriousProton 2a58cad: same results (35 of 40 switched, all 35 end at 0 objects; the same 5 not covered).

🤖 Generated with Claude Code

…d#1465)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

infinite loop during scenario teardown

1 participant