summaryrefslogtreecommitdiff
path: root/src/script/script_instance.hpp
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/script_instance.hpp
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/script_instance.hpp')
-rw-r--r--src/script/script_instance.hpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/script/script_instance.hpp b/src/script/script_instance.hpp
index 56e830367..653ec3884 100644
--- a/src/script/script_instance.hpp
+++ b/src/script/script_instance.hpp
@@ -198,6 +198,8 @@ public:
*/
bool IsSleeping() { return this->suspend != 0; }
+ size_t GetAllocatedMemory() const;
+
protected:
class Squirrel *engine; ///< A wrapper around the squirrel vm.
const char *versionAPI; ///< Current API used by this script.
@@ -241,6 +243,7 @@ private:
int suspend; ///< The amount of ticks to suspend this script before it's allowed to continue.
bool is_paused; ///< Is the script paused? (a paused script will not be executed until unpaused)
Script_SuspendCallbackProc *callback; ///< Callback that should be called in the next tick the script runs.
+ size_t last_allocated_memory; ///< Last known allocated memory value (for display for crashed scripts)
/**
* Call the script Load function if it exists and data was loaded