Error when refreshing all reconstructed objects


At the beginning, I created some objects (such as img, label, cont, etc.) and applied some styles and image resources. In some cases, I need to delete these objects and reload other objects and image resources. However, after two consecutive successes, it crashes in the function lv_style_property_t get_style_prop(const lv_style_t * style, size_t idx).

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


What LVGL version are you using?


What do you want to achieve?

I want to delete these objects and reload other objects and image resources, and keep repeating this process.

What have you tried so far?

I tried to clean up the style list of all objects (including child objects), and then use lv_obj_del() to delete the parent object, but it didn’t improve.

Code to reproduce

Sorry for some reasons, it is not convenient to paste the code.
I want to know what I need to pay attention to if I implement this function (repeatedly create and delete objects, and load different styles and image resources). This is my first time using lvgl, thank you very much!

Screenshot and/or video

Without reproducible code it will be difficult to tell you anything specific, however, I’d check that your lv_style_t variables are not going out of scope/getting deallocated before the object finishes getting deleted.

Thanks for your reply。

Part of the code is like this:
When created:
lv_style_t m_Style;
lv_style_set_bg_opa(&m_Style, LV_STATE_DEFAULT, LV_OPA_0);
lv_style_set_text_font(&m_Style, LV_STATE_DEFAULT, &font_source_han_sans_cn_regular_28);
lv_style_set_text_color(&m_Style, LV_STATE_DEFAULT, lv_color_make(0x9b, 0x9b, 0xa1));

lv_obj_t* m_pLabel= lv_label_create(lv_scr_act(), NULL);
lv_label_set_long_mode(m_pLabel, LV_LABEL_LONG_DOT);
lv_obj_set_size(m_pLabel, 188, 36);
lv_obj_set_style_local_text_opa(m_pLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_70);
lv_label_set_align(m_pLabel, LV_LABEL_ALIGN_CENTER);
lv_obj_add_style(m_pLabel, LV_LABEL_PART_MAIN, &m_Style);

When deleting:
lv_obj_clean_style_list(m_pLabel, LV_LABEL_PART_MAIN);

I don’t know if this is correct.

m_Style needs to be a global variable or be declared static within the function, otherwise it will go out of scope if that function ever returns.

I don’t think you need to call lv_obj_clean_style_list before deleting objects; I’m pretty sure LVGL cleans this up for you.

Your answer helped me, thanks!