Call `lv_page_focus` from `group_objects_focus_callback`

Description

group_objects_focus_callback is the function I set for the group_objects as the focus callback.

void group_objects_focus_callback(lv_group_t *group)
{
   	lv_obj_t *focused_object = lv_group_get_focused(group);
   	lv_page_focus(page_menu, focused_object, 0);
}

consider this:

Objects A, B and C are the members of group_objects.

A is the child of the page_menu.

The focus is on obj B.

when I want to clear the whole screen It seems that it will fist delete the page_menu and then It will try to delete the obj B which will cause to refocus the obj C and eventually call the group_objects_focus_callback.
As there is no page_menu object anymore, this will lead to a hard fault handler.

Is there any better solution for this?

What MCU/Processor/Board and compiler are you using?

MCU: stm32f429igt6
Compiler: GCC
IDE: CubeIDE-eclipse based-

What do you want to achieve?

calling lv_page_focus safely.

What have you tried so far?

Another solution I’m thinking of is instead of using group_focus_callback and call lv_page_focus inside it, calling this function when I catch the LV_EVENT_FOCUSED in the callback of objects that need it in order to be shown. for example, the exit_icon need to be shown when it is focused so in its callback I have this:

static void obj_main_exit_callback(lv_obj_t *obj, lv_event_t event)
{
	 if(event == LV_EVENT_FOCUSED) {
		lv_page_focus(page_menu, obj, 0);
	}
}

But still not sure if there is any situation that this will be called while the page_menu -parent obj- or obj -the child object- are deleted.
what do you think about it?

Please a send a simple code to reproduce this issue.

1 Like

Wow, I wish you wouldn’t ask me this :wink:
OK, I will try to reproduce the issue and put the code here. Thanks

1 Like

He’s asked because it makes it much easier to understand the problem/suggestion. :slightly_smiling_face:

2 Likes

Oh, it’s hard to reproduce the issue. :smirk:
You know, I like my second solution.:upside_down_face: It seems that there is no problem with it.

1 Like