fix sol::error crash

This commit is contained in:
Lion Kortlepel
2026-04-15 18:14:31 +02:00
parent 7096fe058a
commit e260de55af
2 changed files with 10 additions and 6 deletions
+6
View File
@@ -34,6 +34,7 @@
#include <queue>
#include <random>
#include <set>
#include <sol/protected_function_result.hpp>
#include <toml.hpp>
#include <unordered_map>
#include <vector>
@@ -84,6 +85,11 @@ struct TLuaResult {
std::make_shared<std::condition_variable>()
};
void SetErrorMessageFromResult(sol::protected_function_result& Res) {
auto error = Res.get<std::optional<std::string>>();
ErrorMessage = error ? *error : "(unknown error; error object is not a string value)";
}
void MarkAsReady();
void WaitUntilReady();
};
+4 -6
View File
@@ -550,8 +550,8 @@ sol::table TLuaEngine::StateThreadData::Lua_TriggerLocalEvent(const std::string&
Result.set(i, FnRet);
++i;
} else {
sol::error Err = FnRet;
beammp_lua_error(std::string("TriggerLocalEvent: ") + Err.what());
auto ErrStr = FnRet.get<std::optional<std::string>>();
beammp_lua_error(std::string("TriggerLocalEvent: ") + (ErrStr ? *ErrStr : "(unknown error; error object is not a string)"));
}
}
}
@@ -1158,8 +1158,7 @@ void TLuaEngine::StateThreadData::operator()() {
S.second->Result = std::move(Res);
} else {
S.second->Error = true;
sol::error Err = Res;
S.second->ErrorMessage = Err.what();
S.second->SetErrorMessageFromResult(Res);
}
S.second->MarkAsReady();
}
@@ -1222,8 +1221,7 @@ void TLuaEngine::StateThreadData::operator()() {
Result->Result = std::move(Res);
} else {
Result->Error = true;
sol::error Err = Res;
Result->ErrorMessage = Err.what();
Result->SetErrorMessageFromResult(Res);
}
Result->MarkAsReady();
} else {