Page MenuHomeWildfire Games

Allow quitting the random map generation early
ClosedPublic

Authored by elexis on Feb 17 2018, 2:30 PM.

Details

Summary

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.

Test Plan

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

elexis created this revision.Feb 17 2018, 2:30 PM
elexis requested review of this revision.Feb 17 2018, 2:46 PM
Vulcan added a subscriber: Vulcan.Feb 17 2018, 3:34 PM

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/differential/30/display/redirect

same for lobby connect when no internet connection. just saying for now... :)

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.

This revision was not accepted when it landed; it landed in state Needs Review.Feb 19 2018, 4:46 PM
This revision was automatically updated to reflect the committed changes.
Owners added a subscriber: Restricted Owners Package.Feb 19 2018, 4:46 PM