Skip to content

Commit

Permalink
fix(scripting/lua): Fix not closing to-be-closed variables on error
Browse files Browse the repository at this point in the history
  • Loading branch information
kajkul committed Mar 18, 2024
1 parent 8b93ef2 commit 3794861
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions code/components/citizen-scripting-lua/src/LuaScriptRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,22 @@ bool LuaScriptRuntime::RunBookmark(uint64_t bookmark)
}
ScriptTrace("^1SCRIPT ERROR: %s^7\n", err);
ScriptTrace("%s", stackData);
#if LUA_VERSION_NUM >= 504
int resetStatus = lua_resetthread(thread);

std::string resetErr = "error object is not a string";
if (lua_type(thread, -1) == LUA_TSTRING)
{
resetErr = lua_tostring(thread, -1);
}

// We can't just check whether the resetStatus is OK because
// if there was no error lua_resetthread returns the same status it received
if (resetStatus != resumeValue || resetErr != err)
{
ScriptTrace("^1Error while closing to-be-closed varaibles: %s^7\n", resetErr);
}
#endif
}

luaL_unref(L, LUA_REGISTRYINDEX, bookmark);
Expand Down

0 comments on commit 3794861

Please sign in to comment.