New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segfault from protected_function args push #1579
Comments
There's a big problem with Lua references: they are not thread safe. No |
The problem is that the 'RosaServer' project this thing is happening in is entirely single threaded except for the thread that handles console input, and it just uses detours on the game dedicated server it's a mod for. So there's no cross-thread refs going on here |
This issue is seemingly very hard to debug, and I'm unable to produce a test case for this (considering this usage of sol2 is pretty out of the ordinary and this is the only instance of this crash I'm able to find)
The code causing the crash: https://github.com/jpxs-intl/RosaServer/blob/main/RosaServer/hooks.cpp#L1293 where
run
is a sol2 protected_function, changeable from the Lua environment.This issue also doesn't persist in a debug build, and only happens in release mode. I've gathered the debug info with GCC
-g
compiler option.Call stack:
I did some debugging, and while the
&Engine::vehicles[vehicleID]
reference passed torun
is perfectly valid and readable memory, the reference seems to be corrupted somehow after the severalstd::forward
parameter unpacks. By the timestack::push_reference
is hit, the Vehicle reference is somehow nulled out. I could just be wrong though, seeing as the segfault is for some reason in.. the constructor for undefined_metatable. See screenshots:The prior
run
call in that function doesn't undergo a similar segfault and runs completely fine.Compiler is GCC, being built with CMake. Using VS2022 as an IDE w/WSL remote development.
Version of sol2 is latest
develop
branch, but is reproducible on the latestmaster
as well.Attempted using
SOL_ALL_SAFETIES_ON
just to see if it'd do anything considering it worked in a debug build and had no dice.The text was updated successfully, but these errors were encountered: