summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/misc/countedobj.cpp7
-rw-r--r--src/script/api/script_execmode.cpp6
-rw-r--r--src/script/api/script_execmode.hpp2
-rw-r--r--src/script/api/script_testmode.cpp6
-rw-r--r--src/script/api/script_testmode.hpp2
5 files changed, 20 insertions, 3 deletions
diff --git a/src/misc/countedobj.cpp b/src/misc/countedobj.cpp
index 28f614afa..837d1c177 100644
--- a/src/misc/countedobj.cpp
+++ b/src/misc/countedobj.cpp
@@ -25,7 +25,12 @@ int32 SimpleCountedObject::Release()
int32 res = --m_ref_cnt;
assert(res >= 0);
if (res == 0) {
- FinalRelease();
+ try {
+ FinalRelease(); // may throw, for example ScriptTest/ExecMode
+ } catch (...) {
+ delete this;
+ throw;
+ }
delete this;
}
return res;
diff --git a/src/script/api/script_execmode.cpp b/src/script/api/script_execmode.cpp
index 4fb0cc7e2..1bbce807a 100644
--- a/src/script/api/script_execmode.cpp
+++ b/src/script/api/script_execmode.cpp
@@ -30,7 +30,7 @@ ScriptExecMode::ScriptExecMode()
this->SetDoCommandMode(&ScriptExecMode::ModeProc, this);
}
-ScriptExecMode::~ScriptExecMode()
+void ScriptExecMode::FinalRelease()
{
if (this->GetDoCommandModeInstance() != this) {
/* Ignore this error if the script already died. */
@@ -38,5 +38,9 @@ ScriptExecMode::~ScriptExecMode()
throw Script_FatalError("ScriptExecMode object was removed while it was not the latest *Mode object created.");
}
}
+}
+
+ScriptExecMode::~ScriptExecMode()
+{
this->SetDoCommandMode(this->last_mode, this->last_instance);
}
diff --git a/src/script/api/script_execmode.hpp b/src/script/api/script_execmode.hpp
index 6591399d3..84eda5ce2 100644
--- a/src/script/api/script_execmode.hpp
+++ b/src/script/api/script_execmode.hpp
@@ -46,6 +46,8 @@ public:
* in when the instance was created.
*/
~ScriptExecMode();
+
+ virtual void FinalRelease();
};
#endif /* SCRIPT_EXECMODE_HPP */
diff --git a/src/script/api/script_testmode.cpp b/src/script/api/script_testmode.cpp
index 37f296de0..ed643c2d9 100644
--- a/src/script/api/script_testmode.cpp
+++ b/src/script/api/script_testmode.cpp
@@ -30,7 +30,7 @@ ScriptTestMode::ScriptTestMode()
this->SetDoCommandMode(&ScriptTestMode::ModeProc, this);
}
-ScriptTestMode::~ScriptTestMode()
+void ScriptTestMode::FinalRelease()
{
if (this->GetDoCommandModeInstance() != this) {
/* Ignore this error if the script already died. */
@@ -38,5 +38,9 @@ ScriptTestMode::~ScriptTestMode()
throw Script_FatalError("Testmode object was removed while it was not the latest *Mode object created.");
}
}
+}
+
+ScriptTestMode::~ScriptTestMode()
+{
this->SetDoCommandMode(this->last_mode, this->last_instance);
}
diff --git a/src/script/api/script_testmode.hpp b/src/script/api/script_testmode.hpp
index 4ca29d5dc..25c1ddaab 100644
--- a/src/script/api/script_testmode.hpp
+++ b/src/script/api/script_testmode.hpp
@@ -48,6 +48,8 @@ public:
* in when the instance was created.
*/
~ScriptTestMode();
+
+ virtual void FinalRelease();
};
#endif /* SCRIPT_TESTMODE_HPP */