summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium42 <rubidium42@users.noreply.github.com>2021-04-12 20:53:04 +0200
committerGitHub <noreply@github.com>2021-04-12 20:53:04 +0200
commitc4bccd4f70cc369d5b3867f8dac74b0ac1d9ea5c (patch)
tree0f799c0cc08012d4d1e1fcfc3469a11e77fc87ab /src
parente722ea89f0ebda60fd251ee2ba33635df367acd4 (diff)
downloadopenttd-c4bccd4f70cc369d5b3867f8dac74b0ac1d9ea5c.tar.xz
Fix #8874: show a warning when a NewGRF scan is requested multiple times from the console (#9022)
Diffstat (limited to 'src')
-rw-r--r--src/console_cmds.cpp4
-rw-r--r--src/openttd.cpp6
-rw-r--r--src/openttd.h2
3 files changed, 9 insertions, 3 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index f50644cf5..cebf70198 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -1351,7 +1351,9 @@ DEF_CONSOLE_CMD(ConRescanNewGRF)
return true;
}
- RequestNewGRFScan();
+ if (!RequestNewGRFScan()) {
+ IConsoleWarning("NewGRF scanning is already running. Please wait until completed to run again.");
+ }
return true;
}
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 250aa0db3..4d820d4db 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -1450,11 +1450,15 @@ static void DoAutosave()
* done in the game-thread, and not in the draw-thread (which most often
* triggers this request).
* @param callback Optional callback to call when NewGRF scan is completed.
+ * @return True when the NewGRF scan was actually requested, false when the scan was already running.
*/
-void RequestNewGRFScan(NewGRFScanCallback *callback)
+bool RequestNewGRFScan(NewGRFScanCallback *callback)
{
+ if (_request_newgrf_scan) return false;
+
_request_newgrf_scan = true;
_request_newgrf_scan_callback = callback;
+ return true;
}
void GameLoop()
diff --git a/src/openttd.h b/src/openttd.h
index 38c7f8064..77fafab1d 100644
--- a/src/openttd.h
+++ b/src/openttd.h
@@ -81,6 +81,6 @@ void HandleExitGameRequest();
void SwitchToMode(SwitchMode new_mode);
-void RequestNewGRFScan(struct NewGRFScanCallback *callback = nullptr);
+bool RequestNewGRFScan(struct NewGRFScanCallback *callback = nullptr);
#endif /* OPENTTD_H */