I have a requirement to change the font of the label frequently, so I will frequently use lv_obj_add_style()
to change its display font. My frequent calls to lv_obj_add_style()
on the lvgl emulator also cause the program to crash and exit. How can I solve this problem?
Hi @zytao ,
If you repeatedly call lv_obj_add_style()
you will leak memory at a high rate.
I would suggest using the ‘local styles’ for this type of application, lv_obj_set_style_xxxxx()
, these functions operate directly on the objects concerned modifying the objects internal style memory rather than allocating a new style each time if that makes sense? Here is a link to the small section in the documentation about this, at the bottom of the page there is a list of all the functions you call of this type.
So to change the font of your label I would do something like this:
lv_obj_set_style_text_font( your_frequently_changing_label, &your_font, LV_PART_MAIN );
I hope that helps.
Kind Regards,
Pete
Ok, I’ll give it a try.
The cause of the breakdown was shown at that time: Segmentation fault
Thank you very much for your advice. My problem has been solved.