XuNeo / luavgl

lua + lvgl = luavgl An optimized lvgl Lua binding
MIT License
57 stars 13 forks source link

Crash in lv_mem.c #5

Closed gvanem closed 1 year ago

gvanem commented 1 year ago

I'm trying to get this to build and run on Win-10 using MSVC /clang-cl. But have nothing but troubles. But first off, the example on the main page does not even parse with my Lua 5.4: lua.exe test.lua:

lua.exe: test.lua:13: '}' expected (to close '{' at line 8) near 'pad_all'

It should read:

    bg_color = "#112233", -- #RRGGBB, 0xRRGGBB or "#RGB"
    pad_all = 0
}

and not bg_color = "#112233", -- #RRGGBB, 0xRRGGBB or "#RGB",

But then after adding a require "lvgl" at the top, a lua.exe test.lua crashes good inside lv_mem.c. Call-stack:

lvgl!search_suitable_block(struct control_t * control = 0x00000000`00000000, int * fli = 0x000000cc`dedeea20, int * sli = 0x000000cc`dedeea24)+0x40
lvgl!block_locate_free(struct control_t * control = 0x00000000`00000000, unsigned int64 size = 0x38)+0x5e
lvgl!lv_tlsf_malloc(void * tlsf = 0x00000000`00000000, unsigned int64 size = 0x38)+0x3b
lvgl!lv_mem_alloc(unsigned int64 size = 0x38)+0x55
lvgl!lv_obj_class_create_obj(struct _lv_obj_class_t * class_p = 0x00007ffa`d8145098, struct _lv_obj_t * parent = 0x00000000`00000000)+0x2d
lvgl!lv_obj_create(struct _lv_obj_t * parent = 0x00000000`00000000)+0x44
lvgl!luaopen_lvgl(struct lua_State * L = 0x000001ef`00157658)+0x131
lua54_x64!luaD_precall(struct lua_State * L = 0x000001ef`00157658, union StackValue * func = 0x000001ef`00157d80, int nresults = 0n1)+0x22c
lua54_x64!ccall(struct lua_State * L = 0x000001ef`00157658, union StackValue * func = 0x000001ef`00157d80, int nResults = 0n1, int inc = 0n65537)+0x4c
lua54_x64!lua_callk(struct lua_State * L = 0x000001ef`00157658, int nargs = <Value unavailable error>, int nresults = 0n1, int64 ctx = <Value unavailable error>, <function> * k = 0x00000000`00000000)+0x5f
lua54_x64!ll_require(struct lua_State * L = 0x000001ef`00157658)+0x1fc
lua54_x64!luaD_precall(struct lua_State * L = 0x000001ef`00157658, union StackValue * func = 0x000001ef`00157d20, int nresults = 0n0)+0x22c
lua54_x64!luaV_execute(struct lua_State * L = 0x000001ef`00157658, struct CallInfo * ci = 0x000001ef`0017c230)+0x29e4
lua54_x64!ccall(struct lua_State * L = 0x000001ef`00157658, union StackValue * func = 0x000001ef`00157d00, int nResults = 0n-1, int inc = 0n65537)+0x65
lua54_x64!luaD_rawrunprotected(struct lua_State * L = 0x000001ef`00157658, <function> * f = 0x00007ffb`1eeb60c0, void * ud = 0x000000cc`dedef5a0)+0x73
lua54_x64!luaD_pcall(struct lua_State * L = 0x000001ef`00157658, <function> * func = <Value unavailable error>, void * u = <Value unavailable error>, int64 old_top = 0n80, int64 ef = 0n64)+0x40
lua54_x64!lua_pcallk(struct lua_State * L = 0x000001ef`00157658, int nargs = <Value unavailable error>, int nresults = 0n-1, int errfunc = <Value unavailable error>, int64 ctx = 0n0, <function> * k = 0x00000000`00000000)+0x10d
lua!docall(struct lua_State * L = 0x000001ef`00157658, int narg = 0n0, int nres = 0n-1)+0x7c
lua!handle_script(void)+0xfe
lua!pmain(struct lua_State * L = 0x000001ef`00157658)+0x589
lua54_x64!luaD_precall(struct lua_State * L = 0x000001ef`00157658, union StackValue * func = 0x000001ef`00157cc0, int nresults = 0n1)+0x22c
lua54_x64!ccall(struct lua_State * L = 0x000001ef`00157658, union StackValue * func = 0x000001ef`00157cc0, int nResults = 0n1, int inc = 0n65537)+0x4c
lua54_x64!luaD_rawrunprotected(struct lua_State * L = 0x000001ef`00157658, <function> * f = 0x00007ffb`1eeb60c0, void * ud = 0x000000cc`dedef8f0)+0x73
lua54_x64!luaD_pcall(struct lua_State * L = 0x000001ef`00157658, <function> * func = <Value unavailable error>, void * u = <Value unavailable error>, int64 old_top = 0n16, int64 ef = 0n0)+0x40
lua54_x64!lua_pcallk(struct lua_State * L = 0x000001ef`00157658, int nargs = <Value unavailable error>, int nresults = 0n1, int errfunc = <Value unavailable error>, int64 ctx = 0n0, <function> * k = 0x00000000`00000000)+0x10d
lua!main(int argc = <Value unavailable error>, char ** argv = 0x000001ef`00178130)+0xec
lua!invoke_main(void)+0x22
lua!__scrt_common_main_seh(void)+0x10c
KERNEL32!BaseThreadInitThunk+0x14
ntdll!RtlUserThreadStart+0x21

presumably since lv_mem_init() was not called for LV_MEM_CUSTOM == 0.

So I really have no idea how to use this library. Seems not very robust.

And BTW, why is not LuaJIT supported? Much faster AFAICS. And it does not build with LVGL from master. Why not?

XuNeo commented 1 year ago

luavgl mainly targets for embedded devices. As a work in progress, I have only tested the simulator on ubuntu and macos. You may need to follow simulator/lv_conf.h and simulator/lv_drv_conf.h to build your own simulator.

To address your issue, the lua.exe must be built from source together with luavgl.c and make sure lvgl is initialized firstly as shown in simulator/main.c.

The lvgl.lua file in source tree is only meant for linter on vscode with lua extension.

gvanem commented 1 year ago

To address your issue, the lua.exe must be built from source together with luavgl.c

Why?

The lvgl.lua file in source tree is only meant for linter on vscode with lua extension.

I did build a lvgl.dll from the sources. My require "lvgl" did not loadlvgl.lua`.

XuNeo commented 1 year ago

Why?

Or you have to initialize lvgl yourself in lua.exe before require("lvgl"). You can follow the instructions and simulator source code as a startpoint.