Adding Button Matrix to a Group Crashes when LV_INDEV_TYPE_KEYPAD is init before LV_INDEV_TYPE_POINTER

Description

If a LV_INDEV_TYPE_KEYPAD driver is added before a LV_INDEV_TYPE_POINTER, then later on when adding a button matrix object to an object group, the program crashes.

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

Nintendo Switch Howebew system module using libnx, compiled with DevkitA64. Crash also reproduced on lv_sim_visual_studio_sdl

What do you experience?

I registered a LV_INDEV_TYPE_KEYPAD driver then registered a LV_INDEV_TYPE_POINTER.

Later on, when I tried to add a button matrix object to an object group, the program crashes.

What do you expect?

I expect it not to crash simply because of the order of registering my input devices. When I switched the order of the 2 driver initialization, no crash occurred.

Code to reproduce

A code snippet to reproduce the issue in the lv_sim_visual_studio_sdl simulator.

    lv_obj_t* p_buttonMatrix = lv_btnm_create(lv_scr_act(), NULL);
    lv_btnm_set_map(p_buttonMatrix, SOME_BUTTON_MAP_LAYOUT);

    lv_group_t* p_objGroup = lv_group_create();
    lv_group_add_obj(p_objGroup, p_buttonMatrix); // <--- code crashes here
    lv_indev_set_group(kb_indev, p_objGroup);

This order will cause the crash:

    /* If the PC keyboard driver is enabled in`lv_drv_conf.h`
     * add this as an input device. It might be used in some examples. */
#if USE_KEYBOARD
    lv_indev_drv_t kb_drv;
    lv_indev_drv_init(&kb_drv);
    kb_drv.type = LV_INDEV_TYPE_KEYPAD;
    kb_drv.read_cb = keyboard_read;
    kb_indev = lv_indev_drv_register(&kb_drv);
#endif

    /* Add the mouse (or touchpad) as input device
     * Use the 'mouse' driver which reads the PC's mouse*/
    mouse_init();
    lv_indev_drv_t indev_drv;
    lv_indev_drv_init(&indev_drv); /*Basic initialization*/
    indev_drv.type = LV_INDEV_TYPE_POINTER;
    indev_drv.read_cb =
        mouse_read; /*This function will be called periodically (by the library) to get the mouse position and state*/
    lv_indev_drv_register(&indev_drv);

This order runs fine:

    /* Add the mouse (or touchpad) as input device
     * Use the 'mouse' driver which reads the PC's mouse*/
    mouse_init();
    lv_indev_drv_t indev_drv;
    lv_indev_drv_init(&indev_drv); /*Basic initialization*/
    indev_drv.type = LV_INDEV_TYPE_POINTER;
    indev_drv.read_cb =
        mouse_read; /*This function will be called periodically (by the library) to get the mouse position and state*/
    lv_indev_drv_register(&indev_drv);

    /* If the PC keyboard driver is enabled in`lv_drv_conf.h`
     * add this as an input device. It might be used in some examples. */
#if USE_KEYBOARD
    lv_indev_drv_t kb_drv;
    lv_indev_drv_init(&kb_drv);
    kb_drv.type = LV_INDEV_TYPE_KEYPAD;
    kb_drv.read_cb = keyboard_read;
    kb_indev = lv_indev_drv_register(&kb_drv);
#endif

Hi,

Thanks for the report, I fixed in the the master branch.