Why does my LVGL crashes with this code?


lv_obj_t * NotificationBackground[MAX_NOTIFICATION];
lv_obj_t * DeviceNameBackground[MAX_NOTIFICATION];
lv_obj_t * DeviceName_Label[MAX_NOTIFICATION];
lv_obj_t * TextBackground[MAX_NOTIFICATION];
lv_obj_t * Text_Label[MAX_NOTIFICATION];

struct NotificationData notification[MAX_NOTIFICATION];

int numNotifications = 0;
int notificationIndex = 0;

void updateNotification(){
    if (SliderScreenState == 1) {
        for (size_t i = 0; i < numNotifications; i++)
        {
            vTaskDelay(pdMS_TO_TICKS(100));

            NotificationBackground[i] = lv_obj_create(NotificationFrame);
            lv_obj_set_size(NotificationBackground[i],  800*LV_HOR_RES_MAX/1000, 200*LV_VER_RES_MAX/1000);
            lv_obj_align(NotificationBackground[i], LV_ALIGN_TOP_MID, 0*LV_HOR_RES_MAX/1000, 3*i + ((200*LV_VER_RES_MAX/1000)*i));
            lv_obj_clear_flag(NotificationBackground[i], LV_OBJ_FLAG_SCROLLABLE);
            lv_obj_set_style_bg_color(NotificationBackground[i], lv_color_hex(0xCECECE),0);
            lv_obj_set_style_border_color(NotificationBackground[i], lv_color_hex(0xFFFFFF),0);
            lv_obj_set_style_outline_opa(NotificationBackground[i], 0,0);

            DeviceNameBackground[i] = lv_obj_create(NotificationBackground[i]);
            lv_obj_set_size(DeviceNameBackground[i],  220*LV_HOR_RES_MAX/1000, 180*LV_VER_RES_MAX/1000);
            lv_obj_align(DeviceNameBackground[i], LV_ALIGN_CENTER,  -285*LV_HOR_RES_MAX/1000,0*LV_VER_RES_MAX/1000);
            lv_obj_clear_flag(DeviceNameBackground[i], LV_OBJ_FLAG_SCROLLABLE);
            lv_obj_set_style_bg_color(DeviceNameBackground[i], lv_color_hex(0x88AC2E),0);
            lv_obj_set_style_border_color(DeviceNameBackground[i], lv_color_hex(0x9BD900),0);
            lv_obj_set_style_outline_opa(DeviceNameBackground[i], 0,0);

            DeviceName_Label[i] = lv_label_create(DeviceNameBackground[i]);
            lv_label_set_text(DeviceName_Label[i]  , devices[i].device_name);
            lv_obj_set_style_text_font(DeviceName_Label[i]  ,&LV_FONT1_SIZE,0);
            lv_obj_set_style_text_color(DeviceName_Label[i], lv_color_hex(0xFFFFFF),0);
            lv_obj_center(DeviceName_Label[i]);

            TextBackground[i] = lv_obj_create(NotificationBackground[i]);
            lv_obj_set_size(TextBackground[i],  560*LV_HOR_RES_MAX/1000, 180*LV_VER_RES_MAX/1000);
            lv_obj_align(TextBackground[i], LV_ALIGN_CENTER,  115*LV_HOR_RES_MAX/1000,0*LV_VER_RES_MAX/1000);
            lv_obj_clear_flag(TextBackground[i], LV_OBJ_FLAG_SCROLLABLE);
            lv_obj_set_style_bg_color(TextBackground[i], lv_color_hex(0x292878),0);
            lv_obj_set_style_border_color(TextBackground[i], lv_color_hex(0x5453D3),0);
            lv_obj_set_style_outline_opa(TextBackground[i], 0,0);

            Text_Label[i] = lv_label_create(TextBackground[i]);
            lv_label_set_text(Text_Label[i]  , notification[i].text);
            lv_obj_set_style_text_font(Text_Label[i]  ,&LV_FONT1_SIZE,0);
            lv_obj_set_style_text_color(Text_Label[i], lv_color_hex(0xFFFFFF),0);
            lv_obj_center(Text_Label[i]);
        }
    }
}

void addNotification(struct NotificationData newNotification) {
    if (numNotifications < MAX_NOTIFICATION) {
        // Add the new notification to the array
        notification[numNotifications] = newNotification;
        numNotifications++;
    } else {
        lv_obj_clean(NotificationFrame);

        lv_obj_invalidate(NotificationFrame);
        // Delete the oldest notification (the one at index 0)
        for (int i = 0; i < MAX_NOTIFICATION - 1; i++) {
            vTaskDelay(pdMS_TO_TICKS(100));
            notification[i] = notification[i + 1];
        }

        // Add the new notification at the end
        notification[MAX_NOTIFICATION - 1] = newNotification;
    }

    updateNotification();
}

the addNotification is being called in a loop with 100 ms delay

You dont show how loop call , but primary error is vTaskDelay used in code.
Completely forget to use this delays timing!

i figured out there was a mistake on the calling of the addNotification

I am not seeing SliderScreenState declared anywhere in your code.