summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-11-24 17:00:37 +0000
committerrubidium <rubidium@openttd.org>2010-11-24 17:00:37 +0000
commit090d6fb8b7be9906cd4dea1ed152ffc9bac8bef0 (patch)
treec405672538e408932352426daaa4883997546bdd /src/script
parent3330dee7e013d110d36c54a1e833b272a8762cab (diff)
downloadopenttd-090d6fb8b7be9906cd4dea1ed152ffc9bac8bef0.tar.xz
(svn r21311) -Fix [FS#4260]: AIs in an infinite loop in e.g. autosave, but also getting settings and such from info.nut, would not be interrupted after a while causing OpenTTD to seem to not respond
Diffstat (limited to 'src/script')
-rw-r--r--src/script/script_info.cpp21
-rw-r--r--src/script/squirrel.hpp10
2 files changed, 18 insertions, 13 deletions
diff --git a/src/script/script_info.cpp b/src/script/script_info.cpp
index 807c42bc1..152bb02f3 100644
--- a/src/script/script_info.cpp
+++ b/src/script/script_info.cpp
@@ -16,6 +16,11 @@
#include "script_info.hpp"
#include "script_scanner.hpp"
+/** Number of operations to get the author and similar information. */
+static const int MAX_GET_OPS = 1000;
+/** Number of operations to create an instance of an AI. */
+static const int MAX_CREATEINSTANCE_OPS = 100000;
+
ScriptFileInfo::~ScriptFileInfo()
{
free((void *)this->author);
@@ -66,17 +71,17 @@ bool ScriptFileInfo::CheckMethod(const char *name) const
info->main_script = strdup(scanner->GetMainScript());
/* Cache the data the info file gives us. */
- if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetAuthor", &info->author)) return SQ_ERROR;
- if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetName", &info->name)) return SQ_ERROR;
- if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetShortName", &info->short_name)) return SQ_ERROR;
- if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetDescription", &info->description)) return SQ_ERROR;
- if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetDate", &info->date)) return SQ_ERROR;
- if (!info->engine->CallIntegerMethod(*info->SQ_instance, "GetVersion", &info->version)) return SQ_ERROR;
- if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "CreateInstance", &info->instance_name)) return SQ_ERROR;
+ if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetAuthor", &info->author, MAX_GET_OPS)) return SQ_ERROR;
+ if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetName", &info->name, MAX_GET_OPS)) return SQ_ERROR;
+ if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetShortName", &info->short_name, MAX_GET_OPS)) return SQ_ERROR;
+ if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetDescription", &info->description, MAX_GET_OPS)) return SQ_ERROR;
+ if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetDate", &info->date, MAX_GET_OPS)) return SQ_ERROR;
+ if (!info->engine->CallIntegerMethod(*info->SQ_instance, "GetVersion", &info->version, MAX_GET_OPS)) return SQ_ERROR;
+ if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "CreateInstance", &info->instance_name, MAX_CREATEINSTANCE_OPS)) return SQ_ERROR;
/* The GetURL function is optional. */
if (info->engine->MethodExists(*info->SQ_instance, "GetURL")) {
- if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetURL", &info->url)) return SQ_ERROR;
+ if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetURL", &info->url, MAX_GET_OPS)) return SQ_ERROR;
}
return 0;
diff --git a/src/script/squirrel.hpp b/src/script/squirrel.hpp
index 53a74eaaa..d50dc356a 100644
--- a/src/script/squirrel.hpp
+++ b/src/script/squirrel.hpp
@@ -140,11 +140,11 @@ public:
* Call a method of an instance, in various flavors.
* @return False if the script crashed or returned a wrong type.
*/
- bool CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT *ret, int suspend = -1);
- bool CallMethod(HSQOBJECT instance, const char *method_name, int suspend = -1) { return this->CallMethod(instance, method_name, NULL, suspend); }
- bool CallStringMethodStrdup(HSQOBJECT instance, const char *method_name, const char **res, int suspend = -1);
- bool CallIntegerMethod(HSQOBJECT instance, const char *method_name, int *res, int suspend = -1);
- bool CallBoolMethod(HSQOBJECT instance, const char *method_name, bool *res, int suspend = -1);
+ bool CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT *ret, int suspend);
+ bool CallMethod(HSQOBJECT instance, const char *method_name, int suspend) { return this->CallMethod(instance, method_name, NULL, suspend); }
+ bool CallStringMethodStrdup(HSQOBJECT instance, const char *method_name, const char **res, int suspend);
+ bool CallIntegerMethod(HSQOBJECT instance, const char *method_name, int *res, int suspend);
+ bool CallBoolMethod(HSQOBJECT instance, const char *method_name, bool *res, int suspend);
/**
* Check if a method exists in an instance.