From 41dfcad474a1da690644e5c241c2eaf1ed68f361 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 29 Jan 2025 07:36:54 +0300 Subject: [PATCH] fix segfaults due to access to dead lua states (coroutines) --- src/logic/scripting/lua/lua_util.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/logic/scripting/lua/lua_util.cpp b/src/logic/scripting/lua/lua_util.cpp index ce17c1d44..d740165bb 100644 --- a/src/logic/scripting/lua/lua_util.cpp +++ b/src/logic/scripting/lua/lua_util.cpp @@ -1,4 +1,5 @@ #include "lua_util.hpp" +#include "lua_engine.hpp" #include #include @@ -228,6 +229,7 @@ static std::shared_ptr create_lambda_handler(State* L) { return std::shared_ptr( new std::string(name), [=](std::string* name) { + auto L = lua::get_main_state(); requireglobal(L, LAMBDAS_TABLE); pushnil(L); setfield(L, *name); @@ -240,6 +242,7 @@ static std::shared_ptr create_lambda_handler(State* L) { runnable lua::create_runnable(State* L) { auto funcptr = create_lambda_handler(L); return [=]() { + auto L = lua::get_main_state(); if (!get_from(L, LAMBDAS_TABLE, *funcptr, false)) return; call_nothrow(L, 0, 0);