From 64f26f61dc9286941cf1ca64ff78dd35cac5b777 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 a023b30edd..68e345c69d 100644 --- a/libaegisub/include/libaegisub/lua/utils.h +++ b/libaegisub/include/libaegisub/lua/utils.h @@ -124,7 +124,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 69a308efe3..c95f151edd 100644 --- a/src/auto4_lua.cpp +++ b/src/auto4_lua.cpp @@ -517,6 +517,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; } @@ -529,6 +530,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; }