From 502414b567b45e34393a4ba9a95484923160f6b4 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Thu, 31 Aug 2023 11:10:11 +0200 Subject: [PATCH] Fix: [Emscripten] config not saved on exit game (#11248) When changing a Game Option and pressing Exit Game, the changes were not actually stored. This because the post-mainloop code was never executed for Emscripten. --- src/openttd.cpp | 29 +++++++++++++++++------------ src/video/sdl2_v.cpp | 3 +++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/openttd.cpp b/src/openttd.cpp index 3ee2182d8e..5356f38fbd 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -459,6 +459,22 @@ struct AfterNewGRFScan : NewGRFScanCallback { } }; +void PostMainLoop() +{ + WaitTillSaved(); + + /* only save config if we have to */ + if (_save_config) { + SaveToConfig(); + SaveHotkeysToConfig(); + WindowDesc::SaveToConfig(); + SaveToHighScore(); + } + + /* Reset windowing system, stop drivers, free used memory, ... */ + ShutdownGame(); +} + #if defined(UNIX) extern void DedicatedFork(); #endif @@ -785,18 +801,7 @@ int openttd_main(int argc, char *argv[]) VideoDriver::GetInstance()->MainLoop(); - WaitTillSaved(); - - /* only save config if we have to */ - if (_save_config) { - SaveToConfig(); - SaveHotkeysToConfig(); - WindowDesc::SaveToConfig(); - SaveToHighScore(); - } - - /* Reset windowing system, stop drivers, free used memory, ... */ - ShutdownGame(); + PostMainLoop(); return ret; } diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index bad581eef3..eb201f0774 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -607,6 +607,9 @@ void VideoDriver_SDL_Base::LoopOnce() * normally done at the end of the main loop for non-Emscripten. * After that, Emscripten just halts, and the HTML shows a nice * "bye, see you next time" message. */ + extern void PostMainLoop(); + PostMainLoop(); + emscripten_cancel_main_loop(); emscripten_exit_pointerlock(); /* In effect, the game ends here. As emscripten_set_main_loop() caused