diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2024-09-12 10:39:26 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2024-09-12 10:39:26 -0400 |
commit | 034d13bcd77c3cbba00da1ef6c3c59d22f4a689e (patch) | |
tree | 6532e8a7edeb3be7d131a1dec9e31558b39f7d35 | |
parent | f789bf05053c99d550e6d95e9a512c984ea43ed5 (diff) |
Disable happy-path destructor semantics when unwinding C++ stack.
If the C++ runtime is already handling an exception, don't try to launch more
Lua operations.
-rw-r--r-- | indra/llcommon/lua_function.cpp | 8 | ||||
-rw-r--r-- | indra/llcommon/lua_function.h | 5 |
2 files changed, 11 insertions, 2 deletions
diff --git a/indra/llcommon/lua_function.cpp b/indra/llcommon/lua_function.cpp index 380e650360..2557fd0cc9 100644 --- a/indra/llcommon/lua_function.cpp +++ b/indra/llcommon/lua_function.cpp @@ -709,6 +709,11 @@ int lua_metaipair(lua_State* L) LuaState::~LuaState() { + // If we're unwinding the stack due to an exception, don't bother trying + // to call any callbacks -- either Lua or C++. + if (std::uncaught_exceptions() != 0) + return; + /*---------------------------- feature flag ----------------------------*/ if (mFeature) /*---------------------------- feature flag ----------------------------*/ @@ -990,7 +995,8 @@ lua_function(atexit, "atexit(function): " *****************************************************************************/ LuaPopper::~LuaPopper() { - if (mCount) + // If we're unwinding the C++ stack due to an exception, don't pop! + if (std::uncaught_exceptions() == 0 && mCount) { lua_pop(mState, mCount); } diff --git a/indra/llcommon/lua_function.h b/indra/llcommon/lua_function.h index 12e74b5d04..10c201c234 100644 --- a/indra/llcommon/lua_function.h +++ b/indra/llcommon/lua_function.h @@ -172,7 +172,10 @@ public: LuaRemover& operator=(const LuaRemover&) = delete; ~LuaRemover() { - lua_remove(mState, mIndex); + // If we're unwinding the C++ stack due to an exception, don't mess + // with the Lua stack! + if (std::uncaught_exceptions() == 0) + lua_remove(mState, mIndex); } private: |