Skip to content

Commit

Permalink
lua: Don't check_stack in LuaCheckStack destructor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arch1t3cht committed Dec 16, 2024
1 parent 21f8c18 commit 64f26f6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 0 additions & 1 deletion libaegisub/include/libaegisub/lua/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/auto4_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down

0 comments on commit 64f26f6

Please sign in to comment.