diff --git a/src/script/api/script_asyncmode.cpp b/src/script/api/script_asyncmode.cpp index afad59187d..6a2128febc 100644 --- a/src/script/api/script_asyncmode.cpp +++ b/src/script/api/script_asyncmode.cpp @@ -48,8 +48,8 @@ ScriptAsyncMode::ScriptAsyncMode(HSQUIRRELVM vm) void ScriptAsyncMode::FinalRelease() { if (this->GetDoCommandAsyncModeInstance() != this) { - /* Ignore this error if the script already died. */ - if (!ScriptObject::GetActiveInstance()->IsDead()) { + /* Ignore this error if the script is not alive. */ + if (ScriptObject::GetActiveInstance()->IsAlive()) { throw Script_FatalError("Asyncmode object was removed while it was not the latest *Mode object created."); } } diff --git a/src/script/api/script_execmode.cpp b/src/script/api/script_execmode.cpp index 6a34288cb2..007dd1ef58 100644 --- a/src/script/api/script_execmode.cpp +++ b/src/script/api/script_execmode.cpp @@ -31,8 +31,8 @@ ScriptExecMode::ScriptExecMode() void ScriptExecMode::FinalRelease() { if (this->GetDoCommandModeInstance() != this) { - /* Ignore this error if the script already died. */ - if (!ScriptObject::GetActiveInstance()->IsDead()) { + /* Ignore this error if the script is not alive. */ + if (ScriptObject::GetActiveInstance()->IsAlive()) { throw Script_FatalError("ScriptExecMode object was removed while it was not the latest *Mode object created."); } } diff --git a/src/script/api/script_testmode.cpp b/src/script/api/script_testmode.cpp index 70055586fe..a38deff548 100644 --- a/src/script/api/script_testmode.cpp +++ b/src/script/api/script_testmode.cpp @@ -31,8 +31,8 @@ ScriptTestMode::ScriptTestMode() void ScriptTestMode::FinalRelease() { if (this->GetDoCommandModeInstance() != this) { - /* Ignore this error if the script already died. */ - if (!ScriptObject::GetActiveInstance()->IsDead()) { + /* Ignore this error if the script is not alive. */ + if (ScriptObject::GetActiveInstance()->IsAlive()) { throw Script_FatalError("Testmode object was removed while it was not the latest *Mode object created."); } } diff --git a/src/script/script_instance.hpp b/src/script/script_instance.hpp index 8273b67ed0..342cb822b6 100644 --- a/src/script/script_instance.hpp +++ b/src/script/script_instance.hpp @@ -152,6 +152,11 @@ public: */ inline bool IsDead() const { return this->is_dead; } + /** + * Return whether the script is alive. + */ + inline bool IsAlive() const { return !this->IsDead() && !this->in_shutdown; } + /** * Call the script Save function and save all data in the savegame. */