starwing/lua-nanovg

lbind crashes on GC with LuaJIT

dsshubin opened this issue · 1 comments

Tested with VS2012, mingw32 and mingw32-w64 on Windows, LuaJIT-2.0.5.

The application crashes when an GC event occurs. Error example from debug build on VC:
Unhandled exception at 0x00007FF8583FF41F (lua51.dll) in luajit.exe: 0xC0000005: Access violation writing location 0x0000000000000006.

Stack trace:

>	lua51.dll!lj_tab_set(lua_State * L, GCtab * t, const TValue * key) Line 506	C
 	lua51.dll!lua_rawset(lua_State * L, int idx) Line 934	C
 	nvg.dll!lbind_delete(lua_State * L, int idx) Line 1021	C
 	nvg.dll!lbL_gc(lua_State * L) Line 1141	C
 	lua51.dll!lj_BC_FUNCC()	Unknown
 	lua51.dll!gc_call_finalizer(global_State * g, lua_State * L, const TValue * mo, GCobj * o) Line 481	C
 	lua51.dll!gc_finalize(lua_State * L) Line 527	C
 	lua51.dll!lj_gc_step(lua_State * L) Line 691	C
 	lua51.dll!lua_newuserdata(lua_State * L, unsigned __int64 size) Line 696	C
 	nvg.dll!new_paint(lua_State * L, NVGpaint * paint) Line 86	C
 	nvg.dll!LradialGradient(lua_State * L) Line 141	C
 	lua51.dll!lj_BC_FUNCC()	Unknown
 	lua51.dll!lua_pcall(lua_State * L, int nargs, int nresults, int errfunc) Line 1053	C
 	luajit.exe!docall(lua_State * L, int narg, int clear) Line 124	C
 	luajit.exe!handle_script(lua_State * L, char * * argv, int n) Line 289	C
 	luajit.exe!pmain(lua_State * L) Line 538	C
 	lua51.dll!lj_BC_FUNCC()	Unknown
 	lua51.dll!lua_cpcall(lua_State * L, int (lua_State *) * func, void * ud) Line 1075	C
 	luajit.exe!main(int argc, char * * argv) Line 566	C
 	luajit.exe!__tmainCRTStartup() Line 241	C
 	kernel32.dll!00007ff88e571fe4()	Unknown
 	ntdll.dll!00007ff8910fefb1()	Unknown

When I commented out the block with condition LUA_VERSION_NUM < 502, then it working well. But I'm not sure this is the right fix.

it seems that LuaJIT added more and more Lua 5.2+ features, adapte the code to suite all Lua versions is harder, I have to think about solutions :(