Why is a freshly created screen initialized with sizes LV_HOR_RES_MAX,LV_VER_RES_MAX?


If I create a new screen, then it will have the size LV_HOR_RES_MAX*LV_VER_RES_MAX. I would assume it has the size of the particular display, which it is created for.

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

Linux Simulator (SDL)

What LVGL version are you using?


What do you want to achieve?

I would expect, when I create a new screen, that it has the dimensions of the used display initially. (Seems to be synchronisation error after setting the default display).

What have you tried so far?

Just create a screen after setting the default display, but the display is apparently NULL in lv_disp_get_hor_res(lv_disp_t * disp).
Is there a way to prevent it being NULL in lv_disp_get_hor_res ?

Code to reproduce

client code :

        lv_obj_t* s  = lv_obj_create(NULL,NULL);
        lv_coord_t screen_width = lv_obj_get_width(s);
        lv_coord_t screen_height = lv_obj_get_height(s);

        cout << screen_width << endl;
        cout << screen_height << endl;


lv_coord_t lv_disp_get_hor_res(lv_disp_t * disp)
    if(disp == NULL) disp = lv_disp_get_default();

    if(disp == NULL)
        return LV_HOR_RES_MAX;
    else {
        switch(disp->driver.rotated) {
            case LV_DISP_ROT_90:
            case LV_DISP_ROT_270:
                return disp->driver.ver_res;
                return disp->driver.hor_res;

Screenshot and/or video

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

Smells like memory corruption.

lv_obj_create won’t create a screen unless there is actually a default display. Therefore, the fact that it gets into lv_disp_get_hor_res and reaches the return LV_HOR_RES_MAX line suggests that the default display reference is being corrupted along the way.

1 Like

Sorry, seems it was my fault :cold_face:, I forgot to set disp_drv.hor_res (disp_drv.ver_res) in one of my displays. Anyway I am getting confused about when LV_HOR_RES (LV_HOR_RES_MAX) and MONITOR_HOR_RES etc. are used by the driver hal and driver implementation. At least when it comes to the simulator.