summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2009-08-20 10:58:22 +0000
committeryexo <yexo@openttd.org>2009-08-20 10:58:22 +0000
commit8839bdbefdf4fcd1fa4c2d6d35381055049872d7 (patch)
treedd2b4a4dffcfa42c5388e6d6a8faeda5b7b32d4e /src/ai
parent0cb004e1d29da1bdc78b7bff5d567ca70562f412 (diff)
downloadopenttd-8839bdbefdf4fcd1fa4c2d6d35381055049872d7.tar.xz
(svn r17232) -Fix (r17223): Kill an AI when it tries to Sleep / execute a DoCommand during Save() instead of failing to save
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/ai_instance.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index 0562cccb8..da14941d5 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -602,11 +602,25 @@ void AIInstance::Save()
/* We don't want to be interrupted during the save function. */
bool backup_allow = AIObject::GetAllowDoCommand();
AIObject::SetAllowDoCommand(false);
- if (!this->engine->CallMethod(*this->instance, "Save", &savedata)) {
- /* The script crashed in the Save function. We can't kill
- * it here, but do so in the next AI tick. */
+ try {
+ if (!this->engine->CallMethod(*this->instance, "Save", &savedata)) {
+ /* The script crashed in the Save function. We can't kill
+ * it here, but do so in the next AI tick. */
+ SaveEmpty();
+ this->engine->CrashOccurred();
+ return;
+ }
+ } catch (AI_FatalError e) {
+ /* If we don't mark the AI as dead here cleaning up the squirrel
+ * stack could throw AI_FatalError again. */
+ this->is_dead = true;
+ this->engine->ThrowError(e.GetErrorMessage());
+ this->engine->ResumeError();
SaveEmpty();
- this->engine->CrashOccurred();
+ /* We can't kill the AI here, so mark it as crashed (not dead) and
+ * kill it in the next AI tick. */
+ this->is_dead = false;
+ this->engine->CrashOccured();
return;
}
AIObject::SetAllowDoCommand(backup_allow);