From 227824f753d7149d53aa47fafd6292459a24afa0 Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 15 Sep 2009 16:16:28 +0000 Subject: (svn r17544) -Fix [FS#3202]: [NoAI] Crash when doing commands in the 'global' scope --- src/ai/ai_instance.cpp | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'src') 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(1); - if (!this->engine->CreateClassInstance(info->GetInstanceName(), this->controller, this->instance)) { + /* Create the main-class */ + this->instance = MallocT(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; } } -- cgit v1.2.3-70-g09d2