Mercurial > hg > openttd
changeset 13046:a02317f15b22 draft
(svn r17544) -Fix [FS#3202]: [NoAI] Crash when doing commands in the 'global' scope
author | rubidium <rubidium@openttd.org> |
---|---|
date | Tue, 15 Sep 2009 16:16:28 +0000 |
parents | c733626647c1 |
children | 30208da44525 |
files | src/ai/ai_instance.cpp |
diffstat | 1 files changed, 23 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ai/ai_instance.cpp +++ b/src/ai/ai_instance.cpp @@ -135,21 +135,30 @@ 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)) { + 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)) { + 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; - } - - /* Create the main-class */ - this->instance = MallocT<SQObject>(1); - if (!this->engine->CreateClassInstance(info->GetInstanceName(), this->controller, this->instance)) { - this->Died(); - return; } }