Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Crash]: Can't start game with CityGrowthLimiter GS #9720

Closed
Thundo54 opened this issue Nov 27, 2021 · 3 comments · Fixed by #9745
Closed

[Crash]: Can't start game with CityGrowthLimiter GS #9720

Thundo54 opened this issue Nov 27, 2021 · 3 comments · Fixed by #9745
Labels
component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language)

Comments

@Thundo54
Copy link

Thundo54 commented Nov 27, 2021

Version of OpenTTD

12.1 (compiled on RaspberryPi), aarch64 (RP3B+)

Steps to reproduce

  1. Open Scenario Editor
  2. Configure GS CGL
  3. Save scenario
  4. Start game with new scenario
  5. Save game to run in on Raspberry Pi
  6. Start game on RPi3B+ with command /opt/openttd-12.1/build/openttd -D -g /root/.openttd/save/autosave/mygame.sav
  7. Crash while starting game (as dedicated server)

Upload crash files

crash.zip

@glx22
Copy link
Contributor

glx22 commented Nov 27, 2021

Please attach your savegame.

@frosch123
Copy link
Member

I reproduced this, here is a simple scenario that uses 'CityGrowthLimiter v6'
cgl.zip

The bug is triggered by the script in town.nut during static initialisation:

class Town {
        ...
        paxRequired = GSController.GetSetting("min_transport_pax");
        ...
}
  • The script wants to read some script configuration setting during loading of the scenario.
  • OpenTTD is not yet finished loading the scenario and actually thinks it still is in the main menu (GM_MENU).
  • OpenTTD then tries to use the new-game script configuration, instead of the one from the scenario. (this is already wrong)
  • However, this new-game script configuration is not available on dedicated servers, so OpenTTD crashes.

The underlying issue in OpenTTD is actually pretty severe:

  • When loading savegames/scenarios, AI and GS are started inside the saveload code:
    • AIPLChunkHandler::Load
    • GSDTChunkHandler::Load
  • At this point of time, the savegame is not yet completely loaded, AfterLoad did not run yet, ... so the gamestate is still incomplete or even invalid.
  • AI/GS code running at this time get in contact with all kind of invalid data. (static initialisation, script's Load() method)

I think to fix this, loading AI/GS needs to be changed significantly:

  • AIPLChunkHandler::Load and GSDTChunkHandler::Load have to store the raw script data in some temporary location.
  • Loading and starting AI/GS must wait until the end of AfterLoad, when the gamestate is ready.

@frosch123 frosch123 added the component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language) label Nov 27, 2021
@James103
Copy link
Contributor

James103 commented Nov 28, 2021

I can reproduce this with a custom AI specifically made for this, so it is not just limited to the provided Game Script and save game.
Crashing save: test_9720.zip
AI being used: Test AI #9720.zip

When run with -D ::1 -g path\to\the\above\save.sav, OpenTTD version 6953df7 crashes during load with:
Assertion failed at line 94 of D:\a\OpenTTD\OpenTTD\src\ai\ai_config.cpp: strcmp("start_date", name) == 0

Crash log: crash.zip

glx22 added a commit to glx22/OpenTTD that referenced this issue Dec 13, 2021
glx22 added a commit to glx22/OpenTTD that referenced this issue Dec 13, 2021
glx22 added a commit to glx22/OpenTTD that referenced this issue Dec 18, 2021
glx22 added a commit to glx22/OpenTTD that referenced this issue Aug 29, 2022
glx22 added a commit to glx22/OpenTTD that referenced this issue Nov 24, 2022
glx22 added a commit to glx22/OpenTTD that referenced this issue Dec 3, 2022
glx22 added a commit to glx22/OpenTTD that referenced this issue Dec 15, 2022
glx22 added a commit to glx22/OpenTTD that referenced this issue Dec 26, 2022
glx22 added a commit to glx22/OpenTTD that referenced this issue Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants