Repository navigation
[Bug] Lua AddEventHandler drops function references from exports #539
WLVF
started this conversation in
[BUG] FiveM for GTAV Enhanced
Replies: 2 comments 1 reply
|
Thanks, we are looking into this. |
1 reply
|
Hello, |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
In the Lua runtime, AddEventHandler replaces a callable table with its metatable's __call.
Function references received from another resource (e.g. a callback passed through an export) are callable tables, so when the event fires, __call receives the first event argument instead of the reference and InvokeFunctionReference is called with nil.
The same code works when used on Legacy.
Affects client and server (the code is identical in both runtimes, checked in server build 153).
Issue type
Both / Unsure
Repro rate
Always
Server build version
FXServer-early-access b153 win32
OS
WIndows 11 Home 25H2
CPU
AMD Ryzen 9 7900X
GPU
NVIDIA RTX 3080
RAM
64 GB DDR5
Storage type
SSD NVMe
Connection type
Ethernet
ISP and bandwidth
No response
DxDiag
No response
Network graph
No response
Platform
Windows
OS version / distribution
Windows 11 Home 25H2
CPU
AMD Ryzen 9 7900X
RAM
64 GB DDR5
Using txAdmin?
Yes
Hosting provider
Self-hosted
Machine type
None
/perf endpoint output
No response
DDoS protection
No response
ulimit -n value (Linux only)
No response
Docker Compose file (Docker only)
No response
Steps to Reproduce
ensure resource_a, thenensure resource_b, and join the server.Expected Behavior
The callback runs and prints "got hello", as it does on Legacy.
Actual Behavior
The handler errors instead of running:
Evidence
AddEventHandlerInternalin scheduler.lua:and later
eventRoutine(table_unpack(eventData))(line 172).For a function reference,
funcref_mt.__call(t, ...)doesrawget(t, '__cfx_functionReference'), buttis now the first event argument, sorefis nil at line 430 (InvokeFunctionReference(ref, args)).Legacy's scheduler.lua only reads
__callfor debug info and still calls the original handler (handler(table_unpack(data))), which is why it works there.Additional Context
This issue was hit when using NUI callbacks:
In my use case, a HUD resource registers other resources' UI handlers via AddEventHandler('__cfx_nui:' .. name, callback), and every UI-to-Lua call failed.
Workaround:
Wrap the callback in a local function. Example:
Suggested Fix:
Keep the original table as the handler and call it, or only use __call to derive the handler name.
All reactions