Garbage collector is trying to destroy current lua_State* #774
-
I have a thread that is resumed several times (yield is invoked from an interrupt after a delta time from last resume), for some reason the garbage collector is trying to dispose it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Like in Lua, all garbage-collectable objects have to be reachable from global lua_State, even other lua_State threads. The solution is to pin an object in the Registry using |
Beta Was this translation helpful? Give feedback.
Like in Lua, all garbage-collectable objects have to be reachable from global lua_State, even other lua_State threads.
This is best described in chapter '30.1 Multiple Threads' in the latest 'Programming in Lua' book, but that's not available online.
The solution is to pin an object in the Registry using
lua_ref
.It will return an index that you can 'release' later using
lua_unref
when you don't need the thread any more.You can also use this index in
lua_getref
to place the object on the stack.