Lv_label_set_text_fmt crash

Description

lv_label_set_text_fmt crash

What MCU/Processor/Board and compiler are you using?

ESP32

What do you experience?

Guru Meditation Error: Core 0 panic’ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x40113e9e PS : 0x00060f30 A0 : 0x8010a9e7 A1 : 0x3ffaf720
0x40113e9e: lv_draw_label at /home/fzb/esp/esp-idf/project/ESP32/components/lvgl/lvgl/src/lv_draw/lv_draw_label.c:65

A2 : 0x3ffaf828 A3 : 0x00000000 A4 : 0x3ffc2504 A5 : 0x000000ff
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x00000000 A9 : 0x00000000
A10 : 0x00000001 A11 : 0x00000001 A12 : 0x00000008 A13 : 0x3ffaf830
A14 : 0x000100fb A15 : 0x0013011a SAR : 0x0000001e EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff

ELF file SHA256: 5c3c892ac1ff91aa5ab405873591c633ac23876aadee32abba96055fde89b5fd

Backtrace: 0x40113e9b:0x3ffaf720 0x4010a9e4:0x3ffaf810 0x4010059d:0x3ffaf870 0x40100617:0x3ffaf8c0 0x40100640:0x3ffaf910 0x401006cb:0x3ffaf930 0x40100a6d:0x3ffaf960 0x401054cf:0x3ffaf9b0 0x401055d0:0x3ffaf9d0 0x400d6ea7:0x3ffaf9f0 0x400d4a7c:0x3ffafa10
0x40113e9b: lv_draw_label at /home/fzb/esp/esp-idf/project/ESP32/components/lvgl/lvgl/src/lv_draw/lv_draw_label.c:60

0x4010a9e4: lv_label_design at /home/fzb/esp/esp-idf/project/ESP32/components/lvgl/lvgl/src/lv_objx/lv_label.c:1068

0x4010059d: lv_refr_obj at /home/fzb/esp/esp-idf/project/ESP32/components/lvgl/lvgl/src/lv_core/lv_refr.c:517

0x40100617: lv_refr_obj at /home/fzb/esp/esp-idf/project/ESP32/components/lvgl/lvgl/src/lv_core/lv_refr.c:547

0x40100640: lv_refr_obj_and_children at /home/fzb/esp/esp-idf/project/ESP32/components/lvgl/lvgl/src/lv_core/lv_refr.c:459

0x401006cb: lv_refr_area_part at /home/fzb/esp/esp-idf/project/ESP32/components/lvgl/lvgl/src/lv_core/lv_refr.c:397

0x40100a6d: lv_refr_area at /home/fzb/esp/esp-idf/project/ESP32/components/lvgl/lvgl/src/lv_core/lv_refr.c:353
(inlined by) lv_refr_areas at /home/fzb/esp/esp-idf/project/ESP32/components/lvgl/lvgl/src/lv_core/lv_refr.c:278
(inlined by) lv_disp_refr_task at /home/fzb/esp/esp-idf/project/ESP32/components/lvgl/lvgl/src/lv_core/lv_refr.c:171

0x401054cf: lv_task_exec at /home/fzb/esp/esp-idf/project/ESP32/components/lvgl/lvgl/src/lv_misc/lv_task.c:370 (discriminator 1)

0x401055d0: lv_task_handler at /home/fzb/esp/esp-idf/project/ESP32/components/lvgl/lvgl/src/lv_misc/lv_task.c:135

What do you expect?

Code to reproduce

The crash always appears in the second of these two functions. The second is called immediately after the first function.
The crash does not occur every time, but after a while, these two functions work normally for a while, and suddenly appear.
They won’t be called at the same time because I used a mutex.

void desktop_set_temp(int temp)
{
    lv_label_set_text_fmt(topcont_temp_label, "%d℃", temp);
}

void desktop_set_humi(int humi)
{
    lv_label_set_text_fmt(topcont_humi_label, "%d%%", humi);
}

Screenshot and/or video

Can you find what line 60 is of this file? That will be useful for tracking down the issue.

line 60:
void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale,
const char * txt, lv_txt_flag_t flag, lv_point_t * offset, lv_draw_label_txt_sel_t * sel,
lv_draw_label_hint_t * hint, lv_bidi_dir_t bidi_dir)
line 65:
if (txt[0] == ‘\0’) return;
crash on line65,this is lvgl’s code

So the text pointer being passed to lv_draw_label is NULL. Perhaps you are running out of memory? lv_label_set_text_fmt allocates a buffer to store the text in.

but I still have hundreds of kb of memory:joy:

That’s weird then. Can you add something that prints an error inside this if statement and see if it fails?

you mean like this?
if(ext->text == NULL) {
printf(“error! ext->text==NULL\n”);
return;
}

Yes; exactly.

Crashed again and it didn’t print

Weird. My guess would be that the ext structure is getting corrupted by something else in your code. Do you have watchpoints available? Can you put a watchpoint on &ext->text and see when its value changes?

I never broke anything in ext elsewhere because I only used lv_label_set_text_fmt from beginning to end
I would like to ask, if the external thread uses lv_label_set_text_fmt and lv_task also uses lv_label_set_text_fmt, there is no mutex between lv_task and the external thread, but the external thread itself has a mutex, will it crash?

The monitoring point was correct just before the crash

There needs to be a mutex on the thread that calls lv_task_handler (which runs lv_tasks), and the thread that calls lv_label_set_text_fmt. If that’s how you have it set up, there should be no concurrency issues.

I meant that some other part of your application may be unintentionally corrupting part of the ext structure, due to an invalid pointer or some similar issue.

Do you see any suspicious if you enable LV_USE_LOG in lv_conf.h?

I have opened the log, but the log does not print any information

I made some attempts. In the first attempt, my two update functions only update the flag bit. Lv_label_set_text_fmt is executed after the flag bit is detected by one lv_task so that it will not crash. In the second attempt, my two update functions are executed There is a time interval between them so that they do not crash

I think I have solved it, I did not add a mutex on lv_task_handler before

I made the following changes and the program runs fine

xSemaphoreTake(ui_xSemaphore, portMAX_DELAY);
lv_task_handler();
xSemaphoreGive(ui_xSemaphore);

Thank you very much for your kind help!!!

Glad to hear you solved it!