From ec7d75d1aea4e220d0cce205d15922d9b45e3231 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 21 Sep 2013 15:59:28 -0700 Subject: [PATCH] Fix an occasional crash when loading Automation scripts cmd::reg and AssExportFilterChain::Register are not thread-safe, so guard them with a mutex. --- aegisub/src/auto4_lua.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/aegisub/src/auto4_lua.cpp b/aegisub/src/auto4_lua.cpp index b5f76fbe6..17cab26fe 100644 --- a/aegisub/src/auto4_lua.cpp +++ b/aegisub/src/auto4_lua.cpp @@ -66,6 +66,7 @@ #include #include #include +#include #include #include @@ -712,7 +713,12 @@ namespace Automation4 { // LuaFeatureMacro int LuaCommand::LuaRegister(lua_State *L) { - cmd::reg(agi::util::make_unique(L)); + static std::mutex mutex; + auto command = agi::util::make_unique(L); + { + std::lock_guard lock(mutex); + cmd::reg(std::move(command)); + } return 0; } @@ -955,7 +961,12 @@ namespace Automation4 { int LuaExportFilter::LuaRegister(lua_State *L) { - AssExportFilterChain::Register(agi::util::make_unique(L)); + static std::mutex mutex; + auto filter = agi::util::make_unique(L); + { + std::lock_guard lock(mutex); + AssExportFilterChain::Register(std::move(filter)); + } return 0; }