summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorYexo <Yexo@openttd.org>2009-01-23 10:30:50 +0000
committerYexo <Yexo@openttd.org>2009-01-23 10:30:50 +0000
commitda066fab5b55259d43aed6c31a61cf94bbde67e3 (patch)
treecb8cf362cfd5fc6a3d8063a143f7e7e6fdca8de3 /src/script
parent75055f011d96e79763a73fb12ef7e118123f56ee (diff)
downloadopenttd-da066fab5b55259d43aed6c31a61cf94bbde67e3.tar.xz
(svn r15222) -Fix: The squirrel stack was corrupted if an AI called any C++ function during Save().
Diffstat (limited to 'src/script')
-rw-r--r--src/script/squirrel.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp
index aa3344ea2..26196292c 100644
--- a/src/script/squirrel.cpp
+++ b/src/script/squirrel.cpp
@@ -177,6 +177,10 @@ bool Squirrel::Resume(int suspend)
bool Squirrel::CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT *ret, int suspend)
{
+ /* Store the stack-location for the return value. We need to
+ * restore this after saving or the stack will be corrupted
+ * if we're in the middle of a DoCommand. */
+ SQInteger last_target = this->vm->_suspended_target;
/* Store the current top */
int top = sq_gettop(this->vm);
/* Go to the instance-root */
@@ -195,6 +199,8 @@ bool Squirrel::CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT
/* Reset the top, but don't do so for the AI main function, as we need
* a correct stack when resuming. */
if (suspend == -1) sq_settop(this->vm, top);
+ /* Restore the return-value location. */
+ this->vm->_suspended_target = last_target;
return this->vm->_suspended != 0;
}