Skip to content

Commit d9c1cf1

Browse files
authored
Merge pull request #83 from cortex-command-community/lua-crash-fix
Lua Crash Fix
2 parents bd1b1fe + c2b4233 commit d9c1cf1

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2020

2121
- Fixed an issue that could cause post-effects to appear very blurry.
2222

23+
- Fixed a rare crash that could occur depending on Lua garbage collection and async processing.
24+
2325
</details>
2426

2527
## [Release v6.1.0] - 2024/02/15

Source/Lua/LuaAdapters.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "LuabindObjectWrapper.h"
55
#include "LuaMan.h"
66

7+
#include "lj_obj.h"
8+
79
using namespace RTE;
810

911
std::unordered_map<std::string, std::function<LuabindObjectWrapper*(Entity*, lua_State*)>> LuaAdaptersEntityCast::s_EntityToLuabindObjectCastFunctions = {};
@@ -295,11 +297,8 @@ void LuaAdaptersScene::CalculatePathAsync2(Scene* luaSelfObject, const luabind::
295297
// So, luabind::object is a weak reference, holding just a stack and a position in the stack
296298
// This means it's unsafe to store on the C++ side if we do basically anything with the lua state before using it
297299
// As such, we need to store this function somewhere safely within our Lua state for us to access later when we need it
298-
// It looks like Luabind constructs temporary interpreters and really doesn't like if you destroy these luabind objects
299-
// In any case, it's extremely unsafe to use! For example capturing the callback by value into the lambdas causes random crashes
300-
// Even if we did literally nothing with it except capture it into a no-op lambda
301-
// TODO: validate this is still actually the case. Changes to lua may have fixed this
302-
lua_State* luaState = callbackParam.interpreter();
300+
lua_State* luaState = mainthread(G(callbackParam.interpreter())); // Get the main thread for the state, in case we're a temp lua thread
301+
303302
static int currentCallbackId = 0;
304303
int thisCallbackId = currentCallbackId++;
305304
if (luabind::type(callbackParam) == LUA_TFUNCTION && callbackParam.is_valid()) {

external/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
subdir('include')
22
subdir('lib')
33
subdir('sources')
4+
external_inc_dirs += include_directories('sources/LuaJIT-2.1/src')

0 commit comments

Comments
 (0)