summaryrefslogtreecommitdiff
path: root/src/script/api
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/script/api
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/script/api')
-rw-r--r--src/script/api/script_object.cpp2
-rw-r--r--src/script/api/script_object.hpp2
2 files changed, 3 insertions, 1 deletions
diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp
index 67ab7e40d..62a71574f 100644
--- a/src/script/api/script_object.cpp
+++ b/src/script/api/script_object.cpp
@@ -38,7 +38,7 @@ static ScriptStorage *GetStorage()
/* static */ ScriptInstance *ScriptObject::ActiveInstance::active = nullptr;
-ScriptObject::ActiveInstance::ActiveInstance(ScriptInstance *instance)
+ScriptObject::ActiveInstance::ActiveInstance(ScriptInstance *instance) : alc_scope(instance->engine)
{
this->last_active = ScriptObject::ActiveInstance::active;
ScriptObject::ActiveInstance::active = instance;
diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp
index 6725f0ed1..55dd5e39b 100644
--- a/src/script/api/script_object.hpp
+++ b/src/script/api/script_object.hpp
@@ -18,6 +18,7 @@
#include "script_types.hpp"
#include "../script_suspend.hpp"
+#include "../squirrel.hpp"
/**
* The callback function for Mode-classes.
@@ -48,6 +49,7 @@ protected:
~ActiveInstance();
private:
ScriptInstance *last_active; ///< The active instance before we go instantiated.
+ ScriptAllocatorScope alc_scope; ///< Keep the correct allocator for the script instance activated
static ScriptInstance *active; ///< The global current active instance.
};