Change label text color during runtime

Hello,

I’m using lvgl version 8.3.2,
How can I change correctly the color of label text during runtime? If I do as following, it works, but only for a certain time, then the program freezes:

Thank you

static lv_style_t style_screen_label_1_main_main_default;
lv_style_set_text_color(&style_screen_label_1_main_main_default, lv_color_make(0xff, 0x00, 0x00));
lv_obj_add_style(guider_ui.screen_label_1, &style_screen_label_1_main_main_default, LV_PART_MAIN|LV_STATE_DEFAULT);

Maybe it’s because you are calling lv_obj_add_style over and over again?
Maybe you take a look here

phu, so should I always check first if the style is already the same, and only if NOT, add a new style.
I suppose that is not a problem to add multiple times a new style - but a problem if it is the same style?..

Maybe you take a look at the styles doku.

For changing the color (or other properties) of a single widget you can call lv_obj_set_style_local_text_color () with the appropriate parameters.
If you want to change a single property of an existing style, then just change the single property of that style and call lv_obj_invalidate (lv_scr_act ()) to force the update.

If I do following, it freezes immediately (lvgl version 8.3.2):

lv_obj_set_style_text_color(&style_screen_label_1_main_main_default, lv_color_make(0xff, 0xff, 0xff), LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_invalidate(lv_scr_act());