Rotary encoder: lv_group_add_obj operation crashes sometimes

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Rotary encoder: lv_group_add_obj operation crashes sometimes

2,230 Views
gertvb
Contributor III

Good Morning Everyone!

I have a weird crash in my program ( I suspect a memory leak somewhere), dealing with adding objects to a rotary encoder group with lv_group_add_obj

LPC55S69 // GuiGuider V1.3.1-GA // MCUXpresso V11.4.0 build 6237 // LvGL 8.2.0 & 8.0.2

 

I have set up 3 screens in GuiGuider (Dashboard, Config, Charts) basically in a circle, each with 2 buttons.

Left button loads previous screen, Right button loads next screen

E.G. repeatedly clicking the right button will take you : Dashboard -> Config -> Charts -> Dashboard again

And repeatedly clicking on the left button will take you in the opposite sequence.

 

I am using a rotary encoder and in the driver I basically send back to LvGL the following 

data->enc_diff = lvgl_RotaryEncoder_Diff; //+1 for a clockwise step, -1 for a CCW step
data->state = LV_INDEV_STATE_PRESSED;
data->state = LV_INDEV_STATE_RELEASED;

The above all works fine, screens render nicely, and responds to the users input via the rotary encoder . . . .

 

In my events_init.c, in the events_init function I've added code to create the lv_group thats required for the Rotary Encoder events to be processed, as well as linking the group to my rotary encoder

 

And on each button click event in events_init.c I remove all objects from the group before running the code to load the new screen with : lv_group_remove_all_objs(rotary_encoder_focused_objects_group);


And then I add the newly created screen's buttons to the group with :  lv_group_add_obj(rotary_encoder_focused_objects_group, guider_ui.Charts_btn_left);

 

This all works fine, except after about the 6th+n screen changes there is an inevitable crash in lv_group_add_obj, see the attached lvgl_crash_info.txt

I've also attached some source file in the .zip file

 

Ive tried:

1. different versions of lvgl 7.1 8.0.2, 8.2.0

2. deleting the group and creating a new one on each screen change

3. setting the group to default

4. Consulting caffeine and spending endless late hours and early mornings looking at the code

But sadly, all to no avail

 

Kind regards

Gert

A TechExplorer working with Embedded Software and Electronics in Agriculture and Alternative Energy
0 Kudos
2 Replies

2,212 Views
gertvb
Contributor III

I changed the screen load from : lv_scr_load_anim(guider_ui.Charts, LV_SCR_LOAD_ANIM_NONE, 0, 0, true);

To : lv_disp_load_scr(guider_ui.Charts);

And the problem disappeared!!

 

Ran the GUI in the GUIGuider simulator, and it also crashed there after a few screen switches, only thing different is that in the GUIGuider simulator there is no group for the encoder, so I figured the problem was in the screen load

A TechExplorer working with Embedded Software and Electronics in Agriculture and Alternative Energy

2,125 Views
zhenhualuo
NXP Employee
NXP Employee

Hi gertvb, 

Yes, the issue is caused by screen load. When loading a new screen by lv_scr_load_anim() and enabling auto-delete previous screen by setting last parameter to "true", the variable of old screen still points to previous memory address even if the used memory is freed, when loading back to the old screen, lv_obj_is_valid is used to validate the old screen by just checking if the screen variable points to a memory address, then the application will be crash. This bug will be fixed in GUI Guider v1.4.0. the following code can be used in events_init.c is the workaround. 

static void Screen_btn_screen_to_screen2_event_handler(lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e); 
    switch (code)
    {
        case LV_EVENT_CLICKED:
        {
            lv_disp_t * d = lv_obj_get_disp(lv_scr_act());
            if (d->prev_scr == NULL && d->scr_to_load == NULL)
            { 
                setup_scr_screen2(&guider_ui);
                lv_scr_load_anim(guider_ui.screen2, LV_SCR_LOAD_ANIM_NONE, 1, 0, true);
            }
        }
            break;
        default:
            break;
    }
}

Best Regards, 

Zhenhua