aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/base
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2013-09-03 20:28:21 +0200
committerWillem Jan Palenstijn2013-09-05 20:23:42 +0200
commitdd9ab7accbe7671134d6c9303d94f527ef599404 (patch)
treea514809a96bcb83cb52522b4335f929200b92a6d /engines/wintermute/base
parent9b027771557bf308d8aa92ea9c25b30be15b68d6 (diff)
downloadscummvm-rg350-dd9ab7accbe7671134d6c9303d94f527ef599404.tar.gz
scummvm-rg350-dd9ab7accbe7671134d6c9303d94f527ef599404.tar.bz2
scummvm-rg350-dd9ab7accbe7671134d6c9303d94f527ef599404.zip
WINTERMUTE: Don't clean up _scripts mid-iteration
Scripts executing from ScEngine::tick() can call ScEngine::unbreakableTick() via scCallMethod("SaveGame") and applyEvent("BeforeSave"). This recursive execution could cause finished scripts being removed from _scripts while ScEngine::tick() is still iterating over that array.
Diffstat (limited to 'engines/wintermute/base')
-rw-r--r--engines/wintermute/base/scriptables/script_engine.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/engines/wintermute/base/scriptables/script_engine.cpp b/engines/wintermute/base/scriptables/script_engine.cpp
index dd24457d6c..bb819b23e4 100644
--- a/engines/wintermute/base/scriptables/script_engine.cpp
+++ b/engines/wintermute/base/scriptables/script_engine.cpp
@@ -362,6 +362,8 @@ bool ScEngine::tick() {
//////////////////////////////////////////////////////////////////////////
bool ScEngine::tickUnbreakable() {
+ ScScript *oldScript = _currentScript;
+
// execute unbreakable scripts
for (uint32 i = 0; i < _scripts.size(); i++) {
if (!_scripts[i]->_unbreakable) {
@@ -373,9 +375,12 @@ bool ScEngine::tickUnbreakable() {
_scripts[i]->executeInstruction();
}
_scripts[i]->finish();
- _currentScript = nullptr;
+ _currentScript = oldScript;
}
- removeFinishedScripts();
+
+ // NB: Don't remove finished scripts here since we could be recursively
+ // executing scripts. Doing so could invalidate the outer iteration in
+ // ::tick() over _scripts.
return STATUS_OK;
}