daid / daid/EmptyEpsilon

infinite loop during scenario teardown

Open
#1,465 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
869
Forks
222
Avg merge
18h 33m
Merged PRs (30d)
1

Description

@hemmond noticed a possible infinite loop during scenario teardown, a minimal example being

function create()
PlayerSpaceship():setTemplate("Atlantis"):onDestroyed(create)
end
create()

The relevent part of the conversation about potential fixes is below

Starry: probably onDestroyed should only be called if the scenario isn't being torn down
hemmond: Well... OnDestroy callback can also be used to print score of that specified ship upon scenario teardown or ship destruction.
Starry: maybe during scenario shutdown creating new objects should fail?
hemmond: That could work, but also could break scenarios like this which will instantiate and then print values, it will try to instantiate (and fail) and if the code will continue, it will break on the new ship control code print.
hemmond: And if you combine both (badly) when you first create new ship and print its control code and then retrieve score from the old ship, it will just fail on new ship and will not give you the score...
Starry: if end game stats are wanted maybe a OnScenarioEnd callback could be added and then one of the earlier breaking changes
Starry: At least if it's "no objects during scenario teardown" when that breaks it's more obvious as to why.
hemmond: Well... I would prefer to add getServerInfo().scenarioState and if you want to get stats when ship is destroyed and also respawn a new one when it is not during teardown, I'd like to use that scenarioState to wrap my new ship instatiation with an IF statement...
hemmond: Then the "no new objects during teardown" will not hurt me.
hemmond: The loop could be really nasty and hard to track down (as during teardown a lot of stuff is happening), but without a way to sanitise my code to avoid hitting this limitation, this rule can be just as bad as the loop itself.
Starry: What states do you want?
hemmond: Well... at least running/finished(victory/defeat)/teardown
Starry: This may tie into it being awkward for the Web interface to figure out if a script has started

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the minimal Lua example during scenario teardown and trace how onDestroyed callbacks create new objects. Review the discussed alternatives—suppressing callbacks, rejecting new objects, or exposing scenarioState—and establish one consistent lifecycle behavior. Done means teardown cannot loop indefinitely and scripts have a defined way to distinguish running, finished, and teardown states.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
game-dev
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.