Lv_scr_load_anim does not work properly

Lv_scr_load_anim does not work properly in LVGL 7.81 and 7.9, But it works fine on LVGL7.8.0

void test_screen_1(void)
	lv_obj_t* one = lv_obj_create(NULL, NULL); 
	lv_obj_t* label = lv_label_create(one, NULL);       
	lv_obj_set_size(one, LV_HOR_RES, LV_VER_RES);       
	lv_obj_align(label, one, LV_ALIGN_CENTER, 0, 0);   
	lv_obj_set_style_local_bg_color(one, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT,
	lv_label_set_text(label, "ONE");   
	lv_scr_load_anim(one, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0, true);
void test_screen_2(void)
	lv_obj_t* two = lv_obj_create(NULL, NULL);  
	lv_obj_t*  label = lv_label_create(two, NULL);        
	lv_obj_set_size(two, LV_HOR_RES, LV_VER_RES);  
	lv_obj_align(label, two, LV_ALIGN_CENTER, 0, 0);  
	lv_obj_set_style_local_bg_color(two, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT,
	lv_label_set_text(label, "TWO");  
	lv_scr_load_anim(two, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0, true);

static void test_screen_task(struct _lv_task_t* task)
	static bool toggle_flag;
	if (toggle_flag)
	toggle_flag = !toggle_flag;

int main(int argc, char** argv)
	/*Initialize LittlevGL*/
	/*Initialize the HAL for LittlevGL*/

	lv_obj_t * scr = lv_obj_create(lv_scr_act(), NULL);
	lv_obj_set_size(scr, LV_HOR_RES, LV_VER_RES);
	lv_task_create(test_screen_task, 1000, LV_TASK_PRIO_LOW, NULL);

	while (1) {
		/* Periodically call the lv_task handler.
		* It could be done in a timer interrupt or an OS task too.*/
		Sleep(10);       /*Just to let the system breathe */

	return 0;

The following is the error log information

Error: lv_obj_get_disp (lv_obj.c #2126 lv_obj_get_disp())
Error: NULL pointer (0x00000000) (lv_debug.c #127 lv_debug_log_error())

There is a ‘fix’ in lv_scr_load_anim (in lv_disp.c) which causes this error.

Don’t know what the ‘fix’ is good for. Was introduced by kisvegabor himself.

The problem is, that the d->scr_to_load is NULL (in your case), which leads to the error.

A quick fix would be to add a check for d->scr_to_load to the if:

So for lvgl 7.8.1 line 220 in lv_disp.c would be

    if(d->del_prev && act_scr != d->scr_to_load && d->scr_to_load) {

But I don’t know whether this a correct fix for every case.

I merged your PR, thank you!