From 34b1f7a99206d841b0a6aa9472034b1f546b8ce6 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sat, 12 Apr 2025 13:05:33 +0100 Subject: [PATCH] Fix: Make GrfMsg() behave like Debug() when not loading NewGRFs. (#13991) GrfMsg() outputs the currently loading NewGRF and current line/sprite number. This is invalid when not NewGRFs are not actually being loaded. --- src/newgrf.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 55182b8b5a..3dc4fca19f 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -87,7 +87,11 @@ ReferenceThroughBaseContainer> _gted; ///< Tempo */ void GrfMsgI(int severity, const std::string &msg) { - Debug(grf, severity, "[{}:{}] {}", _cur_gps.grfconfig->filename, _cur_gps.nfo_line, msg); + if (_cur_gps.grfconfig == nullptr) { + Debug(grf, severity, "{}", msg); + } else { + Debug(grf, severity, "[{}:{}] {}", _cur_gps.grfconfig->filename, _cur_gps.nfo_line, msg); + } } /** @@ -371,6 +375,7 @@ void GRFUnsafe(ByteReader &) /** Reset and clear all NewGRFs */ static void ResetNewGRF() { + _cur_gps.grfconfig = nullptr; _cur_gps.grffile = nullptr; _grf_files.clear(); @@ -1823,6 +1828,10 @@ void LoadNewGRF(SpriteID load_index, uint num_baseset) } } + /* We've finished reading files. */ + _cur_gps.grfconfig = nullptr; + _cur_gps.grffile = nullptr; + /* Pseudo sprite processing is finished; free temporary stuff */ _cur_gps.ClearDataForNextFile();