sol2
sol2 copied to clipboard
Problem when sol::state is reset
First, thanks a lot for your amazing work! I am one of your sponsors and you deserve support for all the astounding work you did.
I am using sol3 in PlotJuggler. Many of my users are reporting a crash in the Lua engine.
https://github.com/facontidavide/PlotJuggler/issues/545 https://github.com/facontidavide/PlotJuggler/issues/522
The interesting part of the stacktrace is:
#6 Object "plotjuggler", at 0x107be02d2, in LuaCustomFunction::initEngine() + 834
#5 Object "plotjuggler", at 0x107be3026, in void sol::basic_reference<false>::move_assign<false>(sol::basic_reference<false>&&) + 38
#4 Object "plotjuggler", at 0x107c52aa8, in luaL_unref + 40
#3 Object "plotjuggler", at 0x107c2ee90, in lua_rawgeti + 80
#2 Object "libsystem_platform.dylib", at 0x7fff20435d7c, in _sigtramp + 28
This happens when I reset an existing sol::state
here:
https://github.com/facontidavide/PlotJuggler/blob/main/plotjuggler_app/transforms/lua_custom_function.cpp#L12
That initEngine()
method is called more than once.
In Ubuntu, I am not able to reproduce this error and I am start thinking that this happens mostly on Mac (but I am not sure).
Lua: 5.4.3 Sol: 3.2.2
Every time I have seen the combination of crash + luaL_unref
+ lua_rawgeti
with sol mentioned the reason has been that there are some sol::object
or similar still stored somewhere when the engine is being destroyed.
For example see https://github.com/ThePhD/sol2/issues/964#issuecomment-623588362
You should make sure that you are not having any references to lua from C++ through any sol::*
objects, such as sol::object
, sol::function
, sol::table
.
If the code containing sol is small enough and you can reproduce the problem, you could try simply commenting out code until you no longer crash.
Something that also comes to mind is that I hope you are not calling initEngine from an event or code that originates from lua itself. Fell into this trap myself before.
There is so little lua/sol in that repository that it makes me feel like it could be a problem internal to sol. Maybe testing different sol versions (git bisect?) could help find out what the issue is. All the code and locks look fine as far as I see.