Description
I am unclear on how best to update LVGL widgets under a thread.
I have a project where a thread periodically polls the serial port for data and updates the UI.
After some amount of time, my application crashes mostly with what appears to be memory issues.
I created a really simple project that simply shows the current time on a label widget every 500ms under a thread. This simple project also crashes after a period of time.
Here are some of the crash messages:
[Error] (199.920, +199920) lv_tlsf_realloc: Asserted at expression: !block_is_free(block) && "block already marked as free" (in lv_tlsf.c line #1208)
[Error] (199.920, +199920) block_locate_free: Asserted at expression: block_size(block) > size (in lv_tlsf.c line #775)
[Error] (998.580, +998580) search_suitable_block: Asserted at expression: sl_map && "internal error - second level bitmap is null" (in lv_tlsf.c line #577)
What MCU/Processor/Board and compiler are you using?
Raspberry Pi 4
What LVGL version are you using?
Latest
What do you want to achieve?
I would like to know best practice for updating widgets from a thread.
What have you tried so far?
Nothing
Code to reproduce
This is the thread function.
static void *AppThread( void *parameter )
{
int halfseccntr = 50;
char str[ 20 ];
_controlThreadRunning = true;
while ( _terminateControlThread == false )
{
//
// The thread will sleep for 10ms then will see what needs to
// be done before returning to sleep.
//
usleep( 10000 );
lv_tick_inc(10);
//
// Countdown 50 x 10ms (0.5s)
//
if ( halfseccntr-- == 0 )
{
std::time_t t = std::time(0); // get time now
std::tm* now = std::localtime(&t);
sprintf( str, "%02u %02u %02u", now->tm_hour, now->tm_min, now->tm_sec );
lv_label_set_text( ui_lblTime, str );
//
// We enter here every second.
// Do whatever we want to do once per second.
//
halfseccntr = 50;
}
}
}
The thread is created thus:
volatile int rc = 0;
_controlThreadRunning = false;
_terminateControlThread = false;
rc = pthread_create( &_controlThread, NULL, AppThread, NULL );
if ( rc )
{
printf( "Failed to start the main firmware thread !\r\nTerminating this application\r\n" );
pthread_exit( NULL );
}