Removing the last tile from a tileview

I’ve taken over an application where a tileview is used to display a number of notifications about system events. These are dynamic and may be removed upon user acknowledgment.

I am seeing an issue sometimes when removing the last tile, at which point the code is supposed to switch to a different screen, but it sometimes the application crashes before this happens. The crash looks like a use-after-free through the tileview .tile_act pointer – I end up with a SIGSEGV because .tile_act is pointing at a tile where the .spec_attr pointer is 5. The .tile_act pointer looks correct, which is why I’m assuming it’s a stale pointer.

The code clearly assumes that the tileview handles removing all tiles, and I’m guessing this is incorrect. The documentation and examples all seem to be for a more static usage than what this application tries to do.

Before I start making big changes to rework everything, I wonder if someone can provide any insight.

Environment

  • MCU/MPU/Board: Custom i.MX6ULL running Linux
  • LVGL version: 9.2 (but the tileview code is mostly unchanged since then)

Hi @mck , thank you for opening this topic

Could you share a code snippet? This will allow us to try and reproduce exactly what you are observing.

Additionally, even though TileView has not undergone any changes, I strongly recommend testing versions v9.5.0 and v9.6.0, as a great deal has changed since version 9.2.0.

Thanks for your response!

Updating is on the task list, thanks for reminding me.

As for a code snippet, here’s a somewhat simplified version of the code that is used to remove tiles:

uint16_t nofTiles = lv_obj_get_child_count(view->tileView);

if (nofTiles > 1)
{
    uint16_t delIndex = lv_obj_get_index(item->obj->parent);
    uint16_t actIndex = lv_obj_get_index(lv_tileview_get_tile_active(view->tileView));

    for (uint8_t i = delIndex + 1; i < nofTiles; i++)
    {
        lv_obj_t* child = lv_obj_get_child(item->obj->parent->parent, i);
        lv_obj_set_x(child, lv_obj_get_x(child) - SCREEN_WIDTH);
    }

    if (delIndex <= actIndex && actIndex > 0)
    {
        actIndex -= 1;
    }

    lv_tileview_set_tile_by_index(view->tileView, actIndex, 0, LV_ANIM_OFF);
    lv_obj_t *activeScreen = lv_obj_get_child(lv_tileview_get_tile_active(view->tileView), 0);
    [..stuff..]
}
else
{
    [.. no fiddling with the tileview ..]
}

lv_obj_delete(item->obj->parent);

In the case where we have multiple tiles when removing one, we pick another one. Otherwise, well, we just leave it, which is why there is a dangling pointer in the tileview.

I found a workaround that appears to work, but it feels kludgy, and I’d like to understand how we’re actually supposed to do this.

I see three possibilities:

  1. TileView is simply not intended to be used as this application has been written
  2. TileView is supposed to handle when tiles are removed
  3. The user is supposed to take care of deleting tiles

If option 2 is correct, it either seems that there is a bug somewhere in lvgl, or we’re doing something wrong that prevents it from working.

If option 3 is correct, I don’t see how to do this, because neither of lv_tileview_set_tile_by_index or lv_tileview_set_tile will work with a NULL pointer.

It is very likely that there is something fundamental about lvgl that I don’t know or understand because my entire experience with it so far consists of this issue.

Again, thanks for taking the time to help!

Note: I’ve upgraded to v9.5 today because it turned out to be trivial.