From 42f7e53e92b5329aa802436fb4ac643eaddc136d Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Mon, 22 May 2023 09:11:46 +0200 Subject: [PATCH] lua: Don't check_stack in LuaCheckStack destructor This would cause an assertion failure in functions like lua_for_each when the given closure throws an error and thus leaves some values on the stack. This can make Aegisub crash entirely instead of just catching and reporting the error. Instead, these stack_checks can be done manually. --- libaegisub/include/libaegisub/lua/utils.h | 1 - src/auto4_lua.cpp | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libaegisub/include/libaegisub/lua/utils.h b/libaegisub/include/libaegisub/lua/utils.h index c5a65d6e4..cf55e3f4d 100644 --- a/libaegisub/include/libaegisub/lua/utils.h +++ b/libaegisub/include/libaegisub/lua/utils.h @@ -129,7 +129,6 @@ struct LuaStackcheck { void dump(); LuaStackcheck(lua_State *L) : L(L), startstack(lua_gettop(L)) { } - ~LuaStackcheck() { check_stack(0); } }; #else struct LuaStackcheck { diff --git a/src/auto4_lua.cpp b/src/auto4_lua.cpp index 36156288b..370a791e3 100644 --- a/src/auto4_lua.cpp +++ b/src/auto4_lua.cpp @@ -680,6 +680,7 @@ namespace { if (lua_isnumber(L, -1) && lua_tointeger(L, -1) == 3) { lua_pop(L, 1); // just to avoid tripping the stackcheck in debug description = "Attempted to load an Automation 3 script as an Automation 4 Lua script. Automation 3 is no longer supported."; + stackcheck.check_stack(0); return; } @@ -692,6 +693,7 @@ namespace { name = GetPrettyFilename().string(); lua_pop(L, 1); + stackcheck.check_stack(0); // if we got this far, the script should be ready loaded = true; }