It is currently impossible to alt+f4 the game while the random map code is running.
This is due to JS code being ran synchroneously in Evaluate.
Destroying the thread with force is ugly and ends up in the segfault in #4154.
Requiring JS to do callbacks is ugly to and errorprone as every single loop in the entire random map generation database would have to take it into account.
But with Yves we discovered the possibility to interrupt and exit the thread successfully.
Details
- Reviewers
Yves - Commits
- rP21264: Stop the random map generation upon quit request (Alt+F4), refs #4822.
- Trac Tickets
- #4822
Start a game or a visual replay, optionally from command-line and notice you can't end the game unless with the patch applied.
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_SetInterruptCallback
To enforce application limits on the amount of time a script may run. (In this case, the callback may terminate the script by returning false.)
Diff Detail
- Repository
- rP 0 A.D. Public Repository
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
Event Timeline
Successful build - Chance fights ever on the side of the prudent.
Link to build: https://jenkins.wildfiregames.com/job/differential/30/display/redirect
It's even worse with the lobby, since it doesn't render in between while connecting. We have a ticket for that.
(Also after the random map script is finished, the ParseEntities part also hangs. But this one covers the majority and is independent)
The new function is called periodically, but rarely it ignores an Alt+F4, then reliably works on the second signal.
I've read some SDL_QuitRequested doc and threads, but didn't find any clues.
Either way this mechanism should be unharmful and is an important improvement as one couldn't quit the application without force while generating the random map (15-60 seconds, sometimes 3 minutes).
The idea of the patch was discussed with Yves in IRC on 2018-02-17.