Lua: Fix crash on exit

Change-Id: Ia03bcdc79902301f774c829f8dbacb6d625cf6a0
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Marcus Tillmanns
2025-01-28 10:47:08 +01:00
parent 4713c2def8
commit 6a030109f2

View File

@@ -342,7 +342,12 @@ expected_str<sol::protected_function> prepareSetup(
// TODO: only register what the plugin requested
for (const auto &[name, func] : d->m_providers.asKeyValueRange()) {
lua["package"]["preload"][name.toStdString()] = [func = func](const sol::this_state &s) {
return func(s);
sol::state_view lua = s;
// We need to make sure that providers work on the main_thread, otherwise they might
// crash when trying to access the lua state on destruction.
if (isCoroutine(lua))
lua = sol::main_thread(lua);
return func(lua);
};
}