LVGL object creation Seg faults

Important: unclear posts may not receive useful answers.

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 FAQ and read the relevant part of the documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

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

My LVGL application started crashing when the number of lv_obj_create() exceeded 200.

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

gcc, linux

What LVGL version are you using?

8.3

What do you want to achieve?

Create a menu widget with multiple pages and multiple labels

What have you tried so far?

Managed to create menu and subpages and add labels to it, but crashing when I add more labels

Code to reproduce

//porting display interface using lv_drivers fbdev
lv_init();
fbdev_init();
static lv_color_t disp_buf[320240];
static lv_disp_draw_buf_t draw_buf;
static lv_disp_drv_t disp_drv;
lv_disp_draw_buf_init(&draw_buf, disp_buf, NULL, 320
240);
lv_disp_drv_init(&disp_drv);
disp_drv.draw_buf = &draw_buf;
disp_drv.flush_cb = fbdev_flush;
disp_drv.hor_res = 320;
disp_drv.ver_res = 240;
g_disp = lv_disp_drv_register(&disp_drv);

// test code , everything fine until i goes over 290
for (int i = 0; i < 300; i++)
{
lv_obj_create(lv_scr_act());
}

while(1)
{
lv_timer_handler();
sleep(1);
}

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

have you compiled a debugging version and checked where the actual segfault is occurring? If you can do that and provide us with the exact location of the error it would be easier to fix.

I can already see one problem.

static lv_color_t disp_buf[320240];
static lv_disp_draw_buf_t draw_buf;
static lv_disp_drv_t disp_drv;
lv_disp_draw_buf_init(&draw_buf, disp_buf, NULL, 320 240);

IDK what your display buffer size is supposed to be but I can tell you that what you are passing to the draw_buf_init function is wrong.

this is what you should have


#define WIDTH 320
#define HEIGHT 240

lv_init();
fbdev_init();
lv_color_t *disp_buf = (lv_color_t *)malloc(WIDTH * HEIGHT * sizeof(lv_color_t));

static lv_disp_draw_buf_t draw_buf;
static lv_disp_drv_t disp_drv;
lv_disp_draw_buf_init(&draw_buf, disp_buf, NULL, WIDTH * HEIGHT);
lv_disp_drv_init(&disp_drv);
disp_drv.draw_buf = &draw_buf;
disp_drv.flush_cb = fbdev_flush;
disp_drv.hor_res = WIDTH;
disp_drv.ver_res = HEIGHT;
g_disp = lv_disp_drv_register(&disp_drv);

320240 was a copy paste error (320*240). I had #define WIDTH and #define HEIGHT. Just copied only the relevant sample code to show the problem. I found the root cause of the problem and fixed it.
LV_MEM_CUSTOM was disabled in my lv_conf.h and thus lvgl was using lv_mem_alloc() from the fixed size memory pool. So when I create too many objects it was causing out of memory exception.
I enabled LV_MEM_CUSTOM and using malloc/free to solve the problem.

You skip info about target hw. Info gcc,linux is here as im from mars.
And as you write lvconf default is limited memory for objects , then is perfectly ok your code crash on limit arrive.