From bbf3028f89901ac4e8c0de221d626b8eafb809a2 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 14 Dec 2023 20:07:40 +0000 Subject: [PATCH] Fix #11585: Crash when cleaning AI/GS with nested AsyncMode. Do not throw sanity check when in_shutdown is true. This is also applied to ExecMode and TestMode as they follow the same pattern. --- src/script/api/script_asyncmode.cpp | 4 ++-- src/script/api/script_execmode.cpp | 4 ++-- src/script/api/script_testmode.cpp | 4 ++-- src/script/script_instance.hpp | 5 +++++ 4 files changed, 11 insertions(+), 6 deletions(-) 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. */