Lua: Fix threading related crash

This commit is contained in:
Lion Kortlepel
2021-09-16 10:07:04 +02:00
parent 2cf368c2b0
commit 5978665ad6
4 changed files with 28 additions and 13 deletions

View File

@@ -8,6 +8,11 @@ public:
IThreaded()
// invokes operator() on this object
: mThread() { }
~IThreaded() noexcept {
if (mThread.joinable()) {
mThread.join();
}
}
virtual void Start() final {
mThread = std::thread([this] { (*this)(); });

View File

@@ -19,14 +19,15 @@ class TLuaPlugin;
struct TLuaResult {
std::atomic_bool Ready;
std::atomic_bool Error;
std::string ErrorMessage;
// TODO: Add condition_variable
std::any Result;
};
struct TLuaPluginConfig {
static inline const std::string FileName = "PluginConfig.toml";
TLuaStateId StateId;
// TODO: Execute list
// TODO: Add execute list
};
class TLuaEngine : IThreaded {
@@ -49,7 +50,6 @@ private:
StateThreadData(const StateThreadData&) = delete;
[[nodiscard]] std::shared_ptr<TLuaResult> EnqueueScript(const std::shared_ptr<std::string>& Script);
void operator()() override;
~StateThreadData();
private:
std::string mName;