summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2019-04-15 19:49:30 +0200
committerNiels Martin Hansen <nielsm@indvikleren.dk>2019-05-11 15:34:33 +0200
commit140a96b3a0fa652b66c701ac941cebc17ff24622 (patch)
treeec64deb3e7ef5032dc18991cf5bb0d4eede52fb5 /src/ai
parentc9fe6e7b8fde3a23f6aab3b55fd8cca639d49696 (diff)
downloadopenttd-140a96b3a0fa652b66c701ac941cebc17ff24622.tar.xz
Change: Limit memory allocations for each Squirrel instance
This can avoid out-of-memory situations due to single scripts using up the entire address space. Instead, scripts that go above the maximum are killed. The maximum is default 1 GB per script, but can be configured by a setting.
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/ai_instance.cpp1
-rw-r--r--src/ai/ai_scanner.cpp2
2 files changed, 3 insertions, 0 deletions
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index 41a842085..edb7ebce0 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -230,6 +230,7 @@ void AIInstance::Died()
void AIInstance::LoadDummyScript()
{
+ ScriptAllocatorScope alloc_scope(this->engine);
extern void Script_CreateDummy(HSQUIRRELVM vm, StringID string, const char *type);
Script_CreateDummy(this->engine->GetVM(), STR_ERROR_AI_NO_AI_FOUND, "AI");
}
diff --git a/src/ai/ai_scanner.cpp b/src/ai/ai_scanner.cpp
index 1d0fed188..8bd3a4385 100644
--- a/src/ai/ai_scanner.cpp
+++ b/src/ai/ai_scanner.cpp
@@ -31,6 +31,8 @@ void AIScannerInfo::Initialize()
{
ScriptScanner::Initialize("AIScanner");
+ ScriptAllocatorScope alloc_scope(this->engine);
+
/* Create the dummy AI */
free(this->main_script);
this->main_script = stredup("%_dummy");