summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-09-15 16:16:28 +0000
committerrubidium <rubidium@openttd.org>2009-09-15 16:16:28 +0000
commit227824f753d7149d53aa47fafd6292459a24afa0 (patch)
tree0d61efa8fd4ccd8a2f2b0f18d2a846f83aae0182 /src/ai
parent4dfef325ce884cf3521ccc4c829d75ce8ce65136 (diff)
downloadopenttd-227824f753d7149d53aa47fafd6292459a24afa0.tar.xz
(svn r17544) -Fix [FS#3202]: [NoAI] Crash when doing commands in the 'global' scope
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/ai_instance.cpp35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index 9e4b56ddc..384f2b4be 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -135,21 +135,30 @@ AIInstance::AIInstance(AIInfo *info) :
return;
}
- /* Load and execute the script for this AI */
- const char *main_script = info->GetMainScript();
- if (strcmp(main_script, "%_dummy") == 0) {
- extern void AI_CreateAIDummy(HSQUIRRELVM vm);
- AI_CreateAIDummy(this->engine->GetVM());
- } else if (!this->engine->LoadScript(main_script)) {
- this->Died();
- return;
- }
+ try {
+ AIObject::SetAllowDoCommand(false);
+ /* Load and execute the script for this AI */
+ const char *main_script = info->GetMainScript();
+ if (strcmp(main_script, "%_dummy") == 0) {
+ extern void AI_CreateAIDummy(HSQUIRRELVM vm);
+ AI_CreateAIDummy(this->engine->GetVM());
+ } else if (!this->engine->LoadScript(main_script)) {
+ this->Died();
+ return;
+ }
- /* Create the main-class */
- this->instance = MallocT<SQObject>(1);
- if (!this->engine->CreateClassInstance(info->GetInstanceName(), this->controller, this->instance)) {
+ /* Create the main-class */
+ this->instance = MallocT<SQObject>(1);
+ if (!this->engine->CreateClassInstance(info->GetInstanceName(), this->controller, this->instance)) {
+ this->Died();
+ return;
+ }
+ AIObject::SetAllowDoCommand(true);
+ } catch (AI_FatalError e) {
+ this->is_dead = true;
+ this->engine->ThrowError(e.GetErrorMessage());
+ this->engine->ResumeError();
this->Died();
- return;
}
}