Deletion of object

Important: posts that do not use this template will be ignored or closed.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the relevant part of the documentation. We will not respond in detail to posts where you haven’t read the relevant documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.

Description

About a day ago I posted a similar problem with deletion of characters, where there were some inexplicable behavior when I tried to delete an object - in this case a window.

I have a button in the high right corner that I use to delete the current window, but over last few days I have been getting some weird crashes. The weirdest part is that the crash is not at all consistent, but rather random, and I can’t find anything in my code that would cause such behavior - keep in mind that i’m not at all experienced.

Note - this code has worked previously in v6

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

As the video/gif shows I currently run the simulator.

What do you want to achieve?

I would just like to know if the crashes is just caused by some of my faulty code, and then what i’m doing wrong.

What have you tried so far?

I have tried to switch some things around that may have caused it, but it haven’t helped. As an example i tried to switch out the parent: lv_scr_act() //trying to get the current screen, could be the problem with something i’m more certain will work.

I have also tried to find some kind of pattern, like pressing on the edge of the button or something the like, that could be the problem, but again i haven’t had any luck.

Couldn’t find anything about changes to deletion of objects in the documentation.

Code to reproduce

This should be the relevant code, I think
The window shown in the video, with the buttons code included
(there is also other code in the window, but I hope this is all thats needed):

    /*Create a window*/
    winPin = lv_win_create(lv_scr_act(), NULL);
    lv_win_set_header_height        (winPin, 0);
    lv_win_set_title                (winPin, "Add/remove user");                        /*Set the title*/
    lv_win_set_btn_width            (winPin, 0);
    lv_obj_add_style                (winPin, LV_WIN_PART_BG, &style_win_bg);
    lv_obj_add_style                (winPin, LV_WIN_PART_HEADER, &style_win_header);



    //Add control button to the header
    lv_obj_t *close_btnPin = lv_imgbtn_create(winPin, NULL);           /*Add close button and use built-in close action*/
    lv_obj_set_event_cb             (close_btnPin, close_window);
    lv_obj_add_style                (close_btnPin, LV_BTN_PART_MAIN, &style_symbol);
    lv_imgbtn_set_src               (close_btnPin, LV_BTN_STATE_RELEASED, &LV_SYMBOL_CLOSE);
    lv_imgbtn_set_src               (close_btnPin, LV_BTN_STATE_PRESSED, &LV_SYMBOL_CLOSE);
    lv_obj_set_pos                  (close_btnPin, 210, 15);
    lv_obj_set_size                 (close_btnPin, 20, 20);
    lv_obj_set_ext_click_area       (close_btnPin, 3, 3, 3, 3);

The handler for clicks on the button:

void close_window(lv_obj_t* obj, lv_event_t event) {

    if (event == LV_EVENT_RELEASED) {
        if (obj != NULL) {
            if (obj == close_btnBat) {
                lv_obj_del(winBat);
            }
            if (obj == CloseBtnPin) {
                lv_obj_del(winPin);
                lv_slider_set_value(Slider, 0, LV_ANIM_OFF);
            }
            if (obj == CloseBtnCard) {
            }
            if (obj == CloseBtnDrive) {
                lv_obj_del(winDrive);
            }// endif
            if (obj == CloseBtnNav) {
                lv_obj_del(winNav);
                WindowBool = false;
            } // endif
        }
    }
}

Screenshot and/or video

This is a video of the problem (i press the number 9 to update, I dont think it’s the reason it crashes)

.

Try using lv_obj_del_async instead. There are certain cases where an object shouldn’t be deleted directly inside an event handler. lv_obj_del_async does it on the next call to lv_task_handler.

I have just tried out what you suggested by replacing my lv_obj_del with lv_obj_del_async, but it didn’t seem to make a difference. I will try out some different things and see if I can make them work.
Thanks for the suggestion

If you don’t have them on already, I suggest enabling all of the debug settings in lv_conf.h.

Well I have now managed to find the culprit.
As the video shows I have a slider that opens the “number window”, and that was the problem. If i kept the cursor pressed down, still dragging, after the window had opened, the slider would trigger the function, that opened the window, multiple times causing it to crash, when i tried to press either the btnmatrix or the close button (i dont know exactly what crashed).

So i just made a method that would trigger the first time the window was opened, and then prevent further tries.