Possible bug using lv_mem_alloc for display buffers

Description

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

ESP32 - M5Stack Xtensa GCC 8.2

What do you experience?

If I modify the esp32 example to use dynamically allocated buffers instead of static, I experience a panic the first time that lv_task_handler runs. Inspecting the core dump, the stack tends to move around a bit in the lvgl code-base as I change my application code. This feels like a memory overrun bug, and it makes me worried the same overrun is happening in the static memory space it just doesn’t overwriting anything we happen to be using at the moment.

What do you expect?

The demo to run the same as with static buffers.

Code to reproduce

Add a code snippet to reproduce the issue in the simulator. It should contain only the relevant code which can be compiled. Bug reports without code snippets or with erroneous code snippets will not be reviewed.

Use the ```c and ``` tags to format your code:

If I change the demo main.c:

(e.g. this ref)

    static lv_color_t buf1[DISP_BUF_SIZE];
    static lv_color_t buf2[DISP_BUF_SIZE];
    static lv_disp_buf_t disp_buf;
    lv_disp_buf_init(&disp_buf, buf1, buf2, DISP_BUF_SIZE);

To

  lv_color_t* buf1 = (lv_color_t*)lv_mem_alloc(DISP_BUF_SIZE);
  lv_color_t* buf2 = (lv_color_t*)lv_mem_alloc(DISP_BUF_SIZE);
  lv_mem_assert(buf1);
  lv_mem_assert(buf2);
  lv_disp_buf_t disp_buf;
  lv_disp_buf_init(&disp_buf, buf1, buf2, DISP_BUF_SIZE);

Screenshot and/or video

In the core dump:

Think of lv_mem_alloc as a LittlevGL-specific (but otherwise identical) version of malloc, that takes a size in bytes. You should be passing sizeof(lv_color_t)*DISP_BUF_SIZE to it.

Oh my. So much fail :frowning: Thank you :slight_smile: