From 5050bad8ac0a41d066d1aa5842d99acd34094690 Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Sat, 4 Mar 2023 12:52:46 +0100 Subject: [PATCH 1/4] lua: Scroll large dialogs automatically --- src/auto4_base.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/auto4_base.cpp b/src/auto4_base.cpp index 388e1fa3d..043d6ad6e 100644 --- a/src/auto4_base.cpp +++ b/src/auto4_base.cpp @@ -216,6 +216,7 @@ namespace Automation4 { wxWindow *ww = config_dialog->CreateWindow(&w); // generate actual dialog contents s->Add(ww, 0, wxALL, 5); // add contents to dialog w.SetSizerAndFit(s); + w.SetLayoutAdaptationMode(wxDIALOG_ADAPTATION_MODE_ENABLED); w.CenterOnParent(); w.ShowModal(); }); From 79050dfdfb26789fd6496e34f2255ccbcf4cb0e5 Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Sun, 21 May 2023 20:26:20 +0200 Subject: [PATCH 2/4] lua: Fix memory leak on aegisub.cancel() --- src/auto4_lua.h | 4 ++++ src/auto4_lua_assfile.cpp | 15 +++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/auto4_lua.h b/src/auto4_lua.h index 46068173e..787ce3a6b 100644 --- a/src/auto4_lua.h +++ b/src/auto4_lua.h @@ -78,6 +78,8 @@ namespace Automation4 { std::deque pending_commits; /// Lines to delete once processing complete successfully std::vector> lines_to_delete; + /// Lines that were allocated here and need to be deleted if the script is cancelled. + std::vector allocated_lines; /// Create copies of all of the lines in the script info section if it /// hasn't already happened. This is done lazily, since it only needs @@ -118,6 +120,8 @@ namespace Automation4 { /// assumes a Lua representation of AssEntry on the top of the stack, and creates an AssEntry object of it static std::unique_ptr LuaToAssEntry(lua_State *L, AssFile *ass=nullptr); + std::unique_ptr LuaToTrackedAssEntry(lua_State *L); + /// @brief Signal that the script using this file is now done running /// @param set_undo If there's any uncommitted changes to the file, /// they will be automatically committed with this diff --git a/src/auto4_lua_assfile.cpp b/src/auto4_lua_assfile.cpp index 3aef3b769..e73a48920 100644 --- a/src/auto4_lua_assfile.cpp +++ b/src/auto4_lua_assfile.cpp @@ -328,6 +328,12 @@ namespace Automation4 { return result; } + std::unique_ptr LuaAssFile::LuaToTrackedAssEntry(lua_State *L) { + std::unique_ptr e = LuaToAssEntry(L, ass); + allocated_lines.push_back(e.get()); + return e; + } + int LuaAssFile::ObjectIndexRead(lua_State *L) { switch (lua_type(L, 2)) { @@ -453,7 +459,7 @@ namespace Automation4 { // insert CheckBounds(n); - auto e = LuaToAssEntry(L, ass); + auto e = LuaToTrackedAssEntry(L); modification_type |= modification_mask(e.get()); QueueLineForDeletion(n - 1); AssignLine(n - 1, std::move(e)); @@ -542,7 +548,7 @@ namespace Automation4 { for (int i = 1; i <= n; i++) { lua_pushvalue(L, i); - auto e = LuaToAssEntry(L, ass); + auto e = LuaToTrackedAssEntry(L); modification_type |= modification_mask(e.get()); if (lines.empty()) { @@ -586,7 +592,7 @@ namespace Automation4 { new_entries.reserve(n - 1); for (int i = 2; i <= n; i++) { lua_pushvalue(L, i); - auto e = LuaToAssEntry(L, ass); + auto e = LuaToTrackedAssEntry(L); modification_type |= modification_mask(e.get()); InsertLine(new_entries, i - 2, std::move(e)); lua_pop(L, 1); @@ -625,7 +631,7 @@ namespace Automation4 { int LuaAssFile::LuaParseKaraokeData(lua_State *L) { - auto e = LuaToAssEntry(L, ass); + auto e = LuaToTrackedAssEntry(L); auto dia = check_cast_constptr(e.get()); argcheck(L, !!dia, 1, "Subtitle line must be a dialogue line"); @@ -734,6 +740,7 @@ namespace Automation4 { void LuaAssFile::Cancel() { for (auto& line : lines_to_delete) line.release(); + for (AssEntry *line : allocated_lines) delete line; references--; if (!references) delete this; } From 42f7e53e92b5329aa802436fb4ac643eaddc136d Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Mon, 22 May 2023 09:11:46 +0200 Subject: [PATCH 3/4] 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; } From f3d6eea3b90d76b313fc297ada79b72ba174a856 Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Mon, 29 May 2023 14:43:34 +0200 Subject: [PATCH 4/4] Fix AppImage build on CI --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f55dc56bd..f0ad7bdf9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -118,7 +118,7 @@ jobs: if: startsWith(matrix.config.os, 'ubuntu-') run: | sudo apt-get update - sudo apt-get install ninja-build build-essential libx11-dev libwxgtk3.0-gtk3-dev libfreetype6-dev pkg-config libfontconfig1-dev libass-dev libasound2-dev libffms2-dev intltool libboost-all-dev + sudo apt-get install ninja-build build-essential libx11-dev libwxgtk3.0-gtk3-dev libfreetype6-dev pkg-config libfontconfig1-dev libass-dev libasound2-dev libffms2-dev intltool libboost-all-dev libhunspell-dev libuchardet-dev libpulse-dev libopenal-dev libjansson-dev - name: Configure run: meson setup build ${{ matrix.config.args }} -Dbuildtype=${{ matrix.config.buildtype }} @@ -186,7 +186,6 @@ jobs: ./linuxdeploy --appdir appdir --desktop-file=appdir/aegisub.desktop ./appimagetool appdir - # ./appimagetool -g -s appdir --comp xz - name: Upload artifacts - Linux AppImage uses: actions/upload-artifact@v3