summaryrefslogtreecommitdiff
path: root/src/newgrf_industries.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-04-05 12:17:36 +0000
committerfrosch <frosch@openttd.org>2009-04-05 12:17:36 +0000
commit3393da4810d64919e825046131f0c95c6819f736 (patch)
tree1cc4a1ccc51c93195402a4c9330c4b30ef545205 /src/newgrf_industries.cpp
parent5551e3d2c628a6dced769801d37b85272cb19e00 (diff)
downloadopenttd-3393da4810d64919e825046131f0c95c6819f736.tar.xz
(svn r15958) -Fix [FS#2787]: Abort production callback after 0x10000 iterations and show a messagebox blaming the newgrf. (mizipzor)
Diffstat (limited to 'src/newgrf_industries.cpp')
-rw-r--r--src/newgrf_industries.cpp14
1 files changed, 14 insertions, 0 deletions
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;