diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lang/english.txt | 1 | ||||
-rw-r--r-- | src/newgrf_industries.cpp | 14 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt index d99ad1170..8054bae09 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3171,6 +3171,7 @@ STR_BROKEN_VEHICLE_LENGTH :{WHITE}Train '{ STR_NEWGRF_BUGGY :{WHITE}NewGRF '{0:RAW_STRING}' provides incorrect information. STR_NEWGRF_BUGGY_ARTICULATED_CARGO :{WHITE}Cargo/refit information for '{1:ENGINE}' differs from purchase list after construction. This might cause autorenew/-replace to fail refitting correctly. +STR_NEWGRF_BUGGY_ENDLESS_PRODUCTION_CALLBACK :{WHITE}'{1:STRING}' caused an endless loop in the production callback. STR_LOADGAME_REMOVED_TRAMS :{WHITE}Game was saved in version without tram support. All trams have been removed. diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index 88d595893..73397eb7c 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -17,6 +17,8 @@ #include "town.h" #include "company_base.h" #include "command_func.h" +#include "gui.h" +#include "strings_func.h" #include "table/strings.h" @@ -570,6 +572,18 @@ void IndustryProductionCallback(Industry *ind, int reason) object.callback_param2 = reason; for (uint loop = 0;; loop++) { + /* limit the number of calls to break infinite loops. + * 'loop' is provided as 16 bits to the newgrf, so abort when those are exceeded. */ + if (loop >= 0x10000) { + /* display error message */ + SetDParamStr(0, spec->grf_prop.grffile->filename); + SetDParam(1, spec->name); + ShowErrorMessage(STR_NEWGRF_BUGGY_ENDLESS_PRODUCTION_CALLBACK, STR_NEWGRF_BUGGY, 0, 0); + + /* abort the function early, this error isn't critical and will allow the game to continue to run */ + break; + } + SB(object.callback_param2, 8, 16, loop); const SpriteGroup *group = Resolve(spec->grf_prop.spritegroup, &object); if (group == NULL || group->type != SGT_INDUSTRY_PRODUCTION) break; |