Skip to content

Commit

Permalink
Traktor: Fix when closing script manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Jan 1, 2024
1 parent ab9f549 commit b587aae
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions code/Script/Lua/ScriptManagerLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ void ScriptManagerLua::destroy()
T_ANONYMOUS_VAR(Ref< ScriptManagerLua >)(this);
T_FATAL_ASSERT(m_contexts.empty());

// Discard member first since ScriptObjectLua check if
// state is valid when destroying and since we're already
// in the process of shutting down the state we don't
// want the objects to interfere with us.
lua_State* luaState = m_luaState;
m_luaState = nullptr;

// Discard all tags from C++ rtti types.
for (auto& rc : m_classRegistry)
{
Expand All @@ -182,11 +189,10 @@ void ScriptManagerLua::destroy()
m_debugger = nullptr;
m_profiler = nullptr;

luaL_unref(m_luaState, LUA_REGISTRYINDEX, m_objectTableRef);
luaL_unref(luaState, LUA_REGISTRYINDEX, m_objectTableRef);
m_objectTableRef = LUA_NOREF;

lua_close(m_luaState);
m_luaState = nullptr;
lua_close(luaState);
}

void ScriptManagerLua::registerClass(IRuntimeClass* runtimeClass)
Expand Down

0 comments on commit b587aae

Please sign in to comment.