Skip to content

Commit 42f7e53

Browse files
committed
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.
1 parent 79050df commit 42f7e53

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

libaegisub/include/libaegisub/lua/utils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ struct LuaStackcheck {
129129
void dump();
130130

131131
LuaStackcheck(lua_State *L) : L(L), startstack(lua_gettop(L)) { }
132-
~LuaStackcheck() { check_stack(0); }
133132
};
134133
#else
135134
struct LuaStackcheck {

src/auto4_lua.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ namespace {
680680
if (lua_isnumber(L, -1) && lua_tointeger(L, -1) == 3) {
681681
lua_pop(L, 1); // just to avoid tripping the stackcheck in debug
682682
description = "Attempted to load an Automation 3 script as an Automation 4 Lua script. Automation 3 is no longer supported.";
683+
stackcheck.check_stack(0);
683684
return;
684685
}
685686

@@ -692,6 +693,7 @@ namespace {
692693
name = GetPrettyFilename().string();
693694

694695
lua_pop(L, 1);
696+
stackcheck.check_stack(0);
695697
// if we got this far, the script should be ready
696698
loaded = true;
697699
}

0 commit comments

Comments
 (0)