Fix an occasional crash when loading Automation scripts

cmd::reg and AssExportFilterChain::Register are not thread-safe, so
guard them with a mutex.
This commit is contained in:
Thomas Goyne 2013-09-21 15:59:28 -07:00
parent f1ed0e4313
commit ec7d75d1ae
1 changed files with 13 additions and 2 deletions

View File

@ -66,6 +66,7 @@
#include <boost/tokenizer.hpp>
#include <cassert>
#include <cstdint>
#include <mutex>
#include <wx/clipbrd.h>
#include <wx/filefn.h>
@ -712,7 +713,12 @@ namespace Automation4 {
// LuaFeatureMacro
int LuaCommand::LuaRegister(lua_State *L)
{
cmd::reg(agi::util::make_unique<LuaCommand>(L));
static std::mutex mutex;
auto command = agi::util::make_unique<LuaCommand>(L);
{
std::lock_guard<std::mutex> 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<LuaExportFilter>(L));
static std::mutex mutex;
auto filter = agi::util::make_unique<LuaExportFilter>(L);
{
std::lock_guard<std::mutex> lock(mutex);
AssExportFilterChain::Register(std::move(filter));
}
return 0;
}