citizen:/scripting/lua/scheduler.lua:61: attempt to call a nil value (upvalue 'fn')

-1

So the code error is this: Also, the lua code is used for FiveM-coding, using vRP as main framework. The error appeals a function that is on vRP, and the caller is a base-function from the artifacts.

Even so, this is the code of the artifact that triggers the error

Code

How the error looks like

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, 0, 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

css
codeigniter
lua
identify
fivem
asked on Stack Overflow Mar 29, 2021 by solo2k • edited Mar 29, 2021 by solo2k

1 Answer

0

The screenshot of your code shows two calls to getBoundaryFunc

runWithBoundaryStart = getBoundaryFunc(Citizen.SubmitBoundaryStart)
runWithBoundaryEnd = getBoundaryFunc(Citizen.SubmitBoundaryEnd)

In order for fn to become nil either of this funcions must be called without proving the first parameter.

  1. find out wether there are more calls to getBoundaryFunc
  2. find out if its return values are called with nil instead of the expected function value as first parameter
  3. fix that
answered on Stack Overflow Mar 29, 2021 by Piglet

User contributions licensed under CC BY-SA 3.0