lvgl: Crash when swithcing between screenes

Hi.

I’m trying make switching between some screenes (lvgl run on MCU with FreeRTOS, not PC simulator). Basic switching works good. But after some switchings (less then 10) I got crash. Not sure where does problem is, maybe some memory leak (but heap remains unchanged…)?

I have wrote simple tester.

Creating lv_task inside my freertos task:

void lvgl_tft_task(void* arg)
{
	powerHold();
	LCD_power_on();
	lv_init();
	disp_spi_init();
	st7735_init();

	lv_disp_drv_t disp;
	lv_disp_drv_init(&disp);
	disp.disp_flush = st7735b_flush;
	lv_disp_drv_register(&disp);
	buttons_drv_reg;

       // switch each 1 second
	lv_task_create(scr_test_task, 1000, LV_TASK_PRIO_MID, NULL); 

	esp_register_freertos_tick_hook(lv_tick_task);

	while(1)
	{
		vTaskDelay(1);
		lv_task_handler();
	}
}

task itself:

uint8_t UI_cnt = 0;
static void scr_test_task(void *arg)
{
	UI_cnt++;

	printf("UI_cnt: %d\n", UI_cnt);
	LOG("RAM", "memory left: %d\n", get_free_heap_size());

	switch(UI_cnt)
	{
	case 1:
	
		scr1_group = lv_group_create();
		lv_indev_set_group(emulated_kp_indev, scr1_group);
		scr1_menu();
		
		break;
	case 2:

		scr2_group = lv_group_create();
		lv_indev_set_group(emulated_kp_indev, scr2_group);
		scr2_menu();
		
		break;

	default:
	
		UI_cnt = 0;
		
		break;
	}
}

Two different screenes:

// scr1 contains 4 buttons (in general)
void scr1_menu()
{
	printf("scr1_menu\n");
	scr_prepare("scr1_menu"); // PREPARE SCREEN

	// ---------- BUTTON 1
	lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL);		 /*Create a button on the currently loaded screen*/
	lv_obj_set_size(btn1, 100, 24);
	lv_obj_align(btn1, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);

	/*Create a label on the button (the 'label' variable can be reused)*/
	lv_obj_t * label = lv_label_create(btn1, NULL);
	lv_label_set_text(label, "Button1");
	//lv_cont_set_fit(label, true, true);
	lv_btn_set_action(btn1, LV_BTN_ACTION_CLICK, my_action);
	lv_obj_set_free_num(btn1, 1);			   /*Set a unique number for the button*/
	lv_group_add_obj(scr1_group, btn1);

	// ---------- BUTTON 2
	/*Copy the button and set toggled state. (The release action is copied too)*/
	lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), btn1);
	lv_obj_align(btn2, NULL, LV_ALIGN_IN_TOP_MID, 0, 30);
	lv_obj_set_free_num(btn2, 2);			   /*Set a unique number for the button*/

	/*Add a label to the toggled button*/
	label = lv_label_create(btn2, NULL);
	lv_label_set_text(label, "Button2");
	lv_btn_set_action(btn2, LV_BTN_ACTION_CLICK, my_action);
	lv_group_add_obj(scr1_group, btn2);

	// ---------- BUTTON 3
	/*Copy the button and set inactive state.*/
	lv_obj_t * btn3 = lv_btn_create(lv_scr_act(), btn1);
	lv_obj_align(btn3, NULL, LV_ALIGN_IN_TOP_MID, 0, 60);
	lv_obj_set_free_num(btn3, 3);			   /*Set a unique number for the button*/

	/*Add a label to the inactive button*/
	label = lv_label_create(btn3, NULL);
	lv_label_set_text(label, "Button3");
	lv_btn_set_action(btn3, LV_BTN_ACTION_CLICK, my_action);
	lv_group_add_obj(scr1_group, btn3);

	// ---------- BUTTON 4
	/*Copy the button and set inactive state.*/
	lv_obj_t * btn4 = lv_btn_create(lv_scr_act(), btn1);
	lv_obj_align(btn4, NULL, LV_ALIGN_IN_TOP_MID, 0, 90);
	lv_obj_set_free_num(btn4, 4);			   /*Set a unique number for the button*/

	/*Add a label to the inactive button*/
	label = lv_label_create(btn4, NULL);
	lv_label_set_text(label, "Button4");
	lv_btn_set_action(btn4, LV_BTN_ACTION_CLICK, my_action);
	lv_group_add_obj(scr1_group, btn4);
}

// scr2 contains lv_list object 
void scr2_menu()
{
	printf("scr2_menu\n");
	scr_prepare("scr2_menu"); // PREPARE SCREEN

	char buf[50];

	lv_obj_t * label;
	label = lv_label_create(lv_scr_act(), NULL);
	lv_label_set_text(label, "Measure");
	lv_obj_align(label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);

	/*Crate the list*/
	lv_obj_t * list1 = lv_list_create(lv_scr_act(), NULL);
	lv_obj_set_size(list1, 140, 60);
	lv_obj_align(list1, NULL, LV_ALIGN_IN_TOP_MID, 0, 30);

	/*Add list elements*/
	for(uint8_t i = 1; i < 20; i++)
	{
		sprintf(buf, "list#%d", i);
		lv_obj_t * list_btn = lv_list_add(list1, NULL, buf, my_action);
		lv_btn_set_fit(list_btn, false, false);
		lv_obj_set_size(list_btn, 120, 20);
	}


	lv_group_add_obj(scr2_group, list1);

	lv_list_set_sb_mode(list1, LV_SB_MODE_AUTO);
}

screen loader (I suppose there migh be an issue)

static void scr_prepare(char* name)
{
	static lv_obj_t * scr = NULL; //screen handle
	static char* oldname;

	if(name)
	{
		printf("name:%s\n", name);
	}
	else
	{
		printf("name: NULL\n");
	}

	if(oldname)
	{
		printf("oldname:%s\n", oldname);
	}
	else
	{
		printf("oldname: NULL\n");
	}

	if(name == oldname)
	{
	   printf("name == oldname\n");
	   return;
	}

	if(scr)
	{
		lv_obj_clean(scr);
		//lv_obj_del(scr); // I tried this , but result is same
		scr = NULL ;
	}

	scr = lv_obj_create(NULL, NULL);
	lv_scr_load(scr);

	oldname = name;
	return;
}

And here is ouput log:

2018-12-12_14:07:44]UI_cnt: 1
[2018-12-12_14:07:44]I (1996) RAM: memory left: 137628
[2018-12-12_14:07:44]
[2018-12-12_14:07:44]scr1_menu
[2018-12-12_14:07:44]name:scr1_menu
[2018-12-12_14:07:44]oldname: NULL
[2018-12-12_14:07:45]UI_cnt: 2
[2018-12-12_14:07:45]I (2996) RAM: memory left: 137628
[2018-12-12_14:07:45]
[2018-12-12_14:07:45]scr2_menu
[2018-12-12_14:07:45]name:scr2_menu
[2018-12-12_14:07:45]oldname:scr1_menu
[2018-12-12_14:07:46]UI_cnt: 3
[2018-12-12_14:07:46]I (3996) RAM: memory left: 137628
[2018-12-12_14:07:46]
[2018-12-12_14:07:47]UI_cnt: 1
[2018-12-12_14:07:47]I (4996) RAM: memory left: 137628
[2018-12-12_14:07:47]
[2018-12-12_14:07:47]scr1_menu
[2018-12-12_14:07:47]name:scr1_menu
[2018-12-12_14:07:47]oldname:scr2_menu
[2018-12-12_14:07:48]UI_cnt: 2
[2018-12-12_14:07:48]I (5996) RAM: memory left: 137628
[2018-12-12_14:07:48]
[2018-12-12_14:07:48]scr2_menu
[2018-12-12_14:07:48]name:scr2_menu
[2018-12-12_14:07:48]oldname:scr1_menu
[2018-12-12_14:07:49]UI_cnt: 3
[2018-12-12_14:07:49]I (6996) RAM: memory left: 137628
[2018-12-12_14:07:49]
[2018-12-12_14:07:50]UI_cnt: 1
[2018-12-12_14:07:50]I (7996) RAM: memory left: 137628
[2018-12-12_14:07:50]
[2018-12-12_14:07:50]scr1_menu
[2018-12-12_14:07:50]name:scr1_menu
[2018-12-12_14:07:50]oldname:scr2_menu
[2018-12-12_14:07:51]UI_cnt: 2
[2018-12-12_14:07:51]I (8996) RAM: memory left: 137628
[2018-12-12_14:07:51]
[2018-12-12_14:07:51]scr2_menu
[2018-12-12_14:07:51]name:scr2_menu
[2018-12-12_14:07:51]oldname:scr1_menu
[2018-12-12_14:07:51]Guru Meditation Error: Core  0 panic'ed (InstrFetchProhibited). Exception was unhandled.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

I’m a little bit late but in the future enabling USE_LV_LOG in lv_conf.h can help.