lvgl / lv_lib_gif

GIF library for LVGL
MIT License
36 stars 13 forks source link

Delete gif crash on LV_EVENT_LEAVE #13

Closed FlyLu closed 3 years ago

FlyLu commented 3 years ago

When there is no next frame of data, the task will send a LV_EVENT_LEAVE event I deleted the gif object on this event, my program is crashed.

This is original

    if (has_next == 0) {
        lv_event_send(img, LV_EVENT_LEAVE, NULL);
    }
    lv_obj_invalidate(img);
    counter = ext->gif->gce.delay;

I modified this

    if (has_next == 0) {
        lv_event_send(img, LV_EVENT_LEAVE, NULL);
    } else {
        lv_obj_invalidate(img);
        counter = ext->gif->gce.delay;
    }

test code


  void lv_gif_event_cb(struct _lv_obj_t * obj, lv_event_t event)
  {
    if (LV_EVENT_LEAVE != event)  {
      return;
    }

    lv_obj_del(obj);
  }

  lv_obj_t *gif = lv_gif_create_from_file(bg, "z:test.gif");
  lv_obj_set_event_cb(gif, lv_gif_event_cb);

Because there is no way to know the gif is finished, except for LV_EVENT_LEAVE event

kisvegabor commented 3 years ago

Thanks for the report, should be fixed here: 1967de3

FlyLu commented 3 years ago

Wish LVGL do better