Crash after micropython garbage collection in lv_draw_dispatch_layer()

Running lv_bindings_micropython on a custom STM32 based board, seems to work fine until the micropython garbage collection runs and then there’s a hard fault.

I’ve traced the location of the hard fault to lv_draw_dispatch_layer(). See below. The draw_task_head structure contents are garbage.

Breakpoint 6, lv_draw_dispatch_layer (disp=disp@entry=0x20007780, layer=layer@entry=0x20006700)
    at mp_user_modules/lv_binding_micropython/lvgl/src/draw/lv_draw.c:235
235	    lv_draw_task_t * t = layer->draw_task_head;

halted: PC: 0x08037adc
238	    while(t) {
(gdb) p *t
$11 = {next = 0x3b066a63, type = 99, area = {x1 = 1595806640, y1 = -1329389749, x2 = 1437802003, y2 = -977009872}, _real_area = {x1 = -558779194, 
    y1 = -1313520317, x2 = -1236777762, y2 = 1499027906}, clip_area_original = {x1 = 1111638617, y1 = -565071329, x2 = -1337375533, y2 = 917911316}, 
  clip_area = {x1 = 1111644417, y1 = 105005634, x2 = 103441233, y2 = -1335598278}, target_layer = 0x81b13214, draw_unit = 0x51590236, 
  state = 956705379, draw_dsc = 0x14b06463, opa = 50 '2', preferred_draw_unit_id = 177 '\261', preference_score = 128 '\200'}
(gdb) where
#0  lv_draw_dispatch_layer (disp=disp@entry=0x20007780, layer=layer@entry=0x20006700)
    at mp_user_modules/lv_binding_micropython/lvgl/src/draw/lv_draw.c:238
#1  0x08037c9a in lv_draw_dispatch ()
    at mp_user_modules/lv_binding_micropython/lvgl/src/draw/lv_draw.c:218
#2  0x0805a53a in draw_buf_flush (disp=0x20007780)
    at mp_user_modules/lv_binding_micropython/lvgl/src/core/lv_refr.c:1426
#3  0x0805b7b0 in refr_invalid_areas ()
    at mp_user_modules/lv_binding_micropython/lvgl/src/core/lv_refr.c:851
#4  lv_display_refr_timer (tmr=<optimized out>)
    at mp_user_modules/lv_binding_micropython/lvgl/src/core/lv_refr.c:419
#5  0x0804bad8 in lv_timer_exec (timer=0x20007ac0)
    at mp_user_modules/lv_binding_micropython/lvgl/src/misc/lv_timer.c:347
#6  lv_timer_handler () at mp_user_modules/lv_binding_micropython/lvgl/src/misc/lv_timer.c:102
#7  lv_timer_handler () at mp_user_modules/lv_binding_micropython/lvgl/src/misc/lv_timer.c:58

I also had to fix a few build errors. See attached patch.
lvgl_git_diff.txt (5.2 KB)

James.