From 5426cb3baf924f541bccf57aa97c6d4473546f09 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Tue, 9 Mar 2021 15:21:57 +0100 Subject: [PATCH] Fix: abort GRFFileScanner on exiting the game as soon as possible This prevents the window from "freezing" when you close it during the scanning of NewGRFs, as it first would continue the action. --- src/newgrf_config.cpp | 5 ++++- src/openttd.cpp | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index 911d266df0..a0e60ef755 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -603,6 +603,9 @@ public: bool GRFFileScanner::AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) { + /* Abort if the user stopped the game during a scan. */ + if (_exit_game) return false; + GRFConfig *c = new GRFConfig(filename.c_str() + basepath_length); bool added = true; @@ -702,7 +705,7 @@ void DoScanNewGRFFiles(NewGRFScanCallback *callback) /* Yes... these are the NewGRF windows */ InvalidateWindowClassesData(WC_SAVELOAD, 0, true); InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE, GOID_NEWGRF_RESCANNED, true); - if (callback != nullptr) callback->OnNewGRFsScanned(); + if (!_exit_game && callback != nullptr) callback->OnNewGRFsScanned(); DeleteWindowByClass(WC_MODAL_PROGRESS); SetModalProgress(false); diff --git a/src/openttd.cpp b/src/openttd.cpp index 035e8e5ae7..235d36f01b 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1469,6 +1469,8 @@ void GameLoop() ScanNewGRFFiles(_request_newgrf_scan_callback); _request_newgrf_scan = false; _request_newgrf_scan_callback = nullptr; + /* In case someone closed the game during our scan, don't do anything else. */ + if (_exit_game) return; } ProcessAsyncSaveFinish();