Group create and add object issue (not the default)


Adding object to created group gives assert error.

[Error] (0.280, +24) lv_obj_add_flag: Asserted at expression: obj != NULL (The object is NULL) (in lv_obj.c line #222)

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

esp32, simulator

What LVGL version are you using?


What do you want to achieve?

I want to user the LV_SYMBOL_KEYBOARD button to move the focus to different objects of the screen. So i wanted to place in a group all the textareas that i wanted switch between them on LV_EVENT_CANCEL

What have you tried so far?

I have identified properly the cancel button when the KEYBOARD button is pressed.
I have tried to assign a lv_group_t* the function that creates the group and then to add the objects inside. When program runs i got this error above.

I have managed to bypass the issue when instead of creating another group i have user the lv_group_get_default() which by hal_init() on simulator is already set and associated with indev. In this case i did not need to add any textareas or dropdown menu in the group. Why ?

But this leaves me with the 3 questions:

  1. Are everything by default added to the default group which is connected with the indev?

  2. I can not create a second group?

  3. Each group has to be assigned to the indev objects of the hal_init() function

Code to reproduce

lv_group_t* formGroup;
//formGroup=lv_group_get_default(); // this works
formGroup=lv_group_create(); // this does not work on add of object
// init of textarea
lv_group_add_obj(formGroup, mainTextArea);

Maybe you forgot to the following call?:
lv_indev_set_group (indev, g)

This has to be done after you call lv_group_create () and after the lv_group_add_obj (…)

but where is the indev declared? In the hal_init function you have this code

static lv_indev_drv_t indev_drv_1;
  lv_indev_drv_init(&indev_drv_1); /*Basic initialization*/
  indev_drv_1.type = LV_INDEV_TYPE_POINTER;

  /*This function will be called periodically (by the library) to get the mouse position and state*/
  indev_drv_1.read_cb = sdl_mouse_read;
  lv_indev_t *mouse_indev = lv_indev_drv_register(&indev_drv_1);

  static lv_indev_drv_t indev_drv_2;
  lv_indev_drv_init(&indev_drv_2); /*Basic initialization*/
  indev_drv_2.type = LV_INDEV_TYPE_KEYPAD;
  indev_drv_2.read_cb = sdl_keyboard_read;
  lv_indev_t *kb_indev = lv_indev_drv_register(&indev_drv_2);
  lv_indev_set_group(kb_indev, g);

  static lv_indev_drv_t indev_drv_3;
  lv_indev_drv_init(&indev_drv_3); /*Basic initialization*/
  indev_drv_3.type = LV_INDEV_TYPE_ENCODER;
  indev_drv_3.read_cb = sdl_mousewheel_read;
  lv_indev_t * enc_indev = lv_indev_drv_register(&indev_drv_3);
  lv_indev_set_group(enc_indev, g);

So kb_indev is local not global. So i can not use it. Does this mean that all this code has to be repeated. It does not seem correct cause one input dr

Make kb_indev global.

isn’t though that a indev can be assigned only to one group and not to 2?

From the indev.html of the

You need to associate an input device with a group. An input device can send key events to only one group but a group can receive data from more than one input device.

So if i make the kb_indev global i can not use it cause it is already assigned to the default group

By setting the kb_indev as global in main.c and use it as extern other part of program it still
gives the same problem

// in the beginning of the .c file
extern lv_indev_t* kb_indev;

// inside the function
	lv_indev_set_group(kb_indev, formGroup);
	lv_group_add_obj(formGroup, mainTextArea);

[Error] (0.744, +7) lv_obj_add_flag: Asserted at expression: obj != NULL (The object is NULL) (in lv_obj.c line #222)

Perhaps your question about the “group” led me in the wrong direction.

The lv_obj_add_flag has nothing to do with any group issue I think.
Search for lv_obj_add_flag within your code. This function is called with an NULL pointer.

The error comes when you add object into the group if you comment out the line error disapears

	lv_group_add_obj(formGroup, mainTextArea);

Hmm, as far as I can see (checked it with lvgl simulator and demo app),
the lv_obj_add_flag function is not called in succession of lv_group_add_obj.
lv_obj_add_flag is mainly called on creation of the different widgets.

You are correct i had to check for add_flag and it is not inside the add_object to group.

The event_handler of an event was adding a flag to an object not created at that time.
I have switched the order and i do not have this error.

The only strange thing is the default group does not give this specific behaviour , so when i was not controlling the groups at all then i did not have at all this problem.
So probably the question is change to adding object to default group by framework does not have issue with event handler (i seems normal cause event handlers are created by users later) but when you the group is done by user the event handler is problem maybe it is only problem of order declaration?
I mean if you create the object and add it to the group before you declare the callback.