问题描述
所以代码错误是这样的: 此外,lua 代码用于 FiveM 编码,使用 vRP 作为主要框架。 该错误涉及 vRP 上的一个函数,而调用方是工件中的基函数。
即便如此,这也是触发错误的神器代码
local GetGameTimer = GetGameTimer
local _sbs = Citizen.SubmitBoundaryStart
local coresume,costatus = coroutine.resume,coroutine.status
local debug = debug
local coroutine_close = coroutine.close or (function(c) end) -- 5.3 compatibility
local hadThread = false
local curTime = 0
-- setup msgpack compat
msgpack.set_string('string_compat')
msgpack.set_integer('unsigned')
msgpack.set_array('without_hole')
msgpack.setoption('empty_table_as_array',true)
-- setup json compat
json.version = json._VERSION -- Version compatibility
json.setoption("empty_table_as_array",true)
json.setoption('with_hole',true)
-- temp
local _in = Citizen.InvokeNative
local function FormatStackTrace()
return _in(`FORMAT_STACK_TRACE` & 0xFFFFFFFF,nil,Citizen.ResultAsString())
end
local function ProfilerEnterScope(scopeName)
return _in(`PROFILER_ENTER_SCOPE` & 0xFFFFFFFF,scopeName)
end
local function ProfilerExitScope()
return _in(`PROFILER_EXIT_SCOPE` & 0xFFFFFFFF)
end
local newThreads = {}
local threads = setmetatable({},{
-- This circumvents undefined behaviour in "next" (and therefore "pairs")
__newindex = newThreads,-- This is needed for CreateThreadNow to work correctly
__index = newThreads
})
local boundaryIdx = 1
local runningThread
local function dummyUseBoundary(idx)
return nil
end
local function getBoundaryFunc(bfn,bid)
return function(fn,...)
local boundary = bid or (boundaryIdx + 1)
boundaryIdx = boundaryIdx + 1
bfn(boundary,coroutine.running())
local wrap = function(...)
dummyUseBoundary(boundary)
local v = table.pack(fn(...))
return table.unpack(v)
end
local v = table.pack(wrap(...))
bfn(boundary,nil)
return table.unpack(v)
end
end
解决方法
您的代码的屏幕截图显示了对 getBoundaryFunc
的两次调用
runWithBoundaryStart = getBoundaryFunc(Citizen.SubmitBoundaryStart)
runWithBoundaryEnd = getBoundaryFunc(Citizen.SubmitBoundaryEnd)
为了使 fn
变为 nil,必须在不证明第一个参数的情况下调用任何一个函数。
- 了解是否有更多对
getBoundaryFunc
的调用 - 找出是否使用 nil 而不是预期的函数值作为第一个参数调用其返回值
- 解决这个问题