In LVGL, there is an occasional error when clicking a button to switch pages. This issue appeared in LVGL version 8.2 and still persists in version 8.3.9. Below is the error message that occurs. Please help analyze this. Thank you.
Perhaps you need to lock your threads?
The lv_timer_handler();
function and the lv_tick_inc(1);
function in my code are mutually locked using mutexes, is that what you’re referring to? Even after adding the mutexes, it still doesn’t work.
Yes, thats what I mean.
… a mutex […] should be invoked before the call of
lv_timer_handler
and released after it. Also, you have to use the same mutex in other tasks and threads around every LVGL (lv_...
) related function call and code
So from my understanding, you need to lock like this:
mutex_lock(&lvgl_mutex);
lv_task_handler();
mutex_unlock(&lvgl_mutex);
//most places in code where you use LVGL:
mutex_lock(&lvgl_mutex);
/* change to the next image */
lv_img_set_src(img, next_image);
mutex_unlock(&lvgl_mutex);
its not necessary to lock lv_tick_inc(1)
Now, since you (likely) switch pages in an event to a click, you don’t need to lock there. Because events are thread safe. But still, a crash that occurs only sometimes can point to concurrent calling of LVGL functions.
from the docs
How so?. If I modify a widget in LVGL inside of the event and meanwhile another thread modifies the same widget the same way that is going to cause an issue. Yes you can modify a widget in an event and not have to worry about it clashing with a thread calling lv_task_handler
unless the function is being called from 2 different threads, I believe there are safeguards for that specific thing happening tho.
No part of LVGL is 100% thread safe you still have to be cautious of how things are coded even if dealing with events.
Thank you for your response. I will test and provide you with the final results.
I’m referring to this statement from the docs;
However, in the following conditions it’s valid to call LVGL related functions:
- In events. Learn more in Events.
It may still be necessary to lock.