进行删除控件时候,代码崩溃

lv_obj_del_async(obj_dialog);和 lv_obj_del(obj_dialog);都会概率性的导致代码崩溃。

请问有同学遇到类似问题吗?都是怎么解决的?

具体要看你的代码是怎么编写的,这种问题一般都是由于在对象被删除了之后仍在继续使用该对象的指针导致的

void Prompt::ShowDialogBox(lv_event_cb_t event_cb_1, lv_event_cb_t event_cb_2, const char *text_1, const char *text_2)

{

lv_obj_t *obj;

lv_obj_t *obj_bg;

lv_color_t color;

lv_color_t text_color;

text_color.full = 0xffffffff;

color.full = 0xFF000000;

if (obj_info)

{

    pthread_mutex_lock(&lock);

    lv_obj_del(obj_info);

    obj_info = NULL;

    pthread_mutex_unlock(&lock);

}

if (obj_dialog)

{

    pthread_mutex_lock(&lock);

    lv_obj_del(obj_dialog);

    obj_dialog = NULL;

    pthread_mutex_unlock(&lock);

}

obj_dialog = obj = lv_obj_create(lv_scr_act());

lv_obj_clear_flag(obj_dialog, LV_OBJ_FLAG_SCROLLABLE);

lv_obj_set_size(obj, LV_HOR_RES, LV_VER_RES);

lv_obj_align(obj, LV_ALIGN_CENTER, 0, 0);

lv_obj_set_style_bg_color(obj, color, 0);

lv_obj_set_style_border_color(obj, color, 0);

lv_obj_set_style_radius(obj, 0, 0);

lv_obj_set_style_bg_opa(obj, LV_OPA_60, 0);

lv_obj_add_event_cb(obj, event_cb_1, LV_EVENT_CLICKED, NULL);

static lv_style_t style;

lv_style_init(&style);

lv_style_reset(&style); // 重置样式

lv_style_set_radius(&style, 0); // 设置样式圆角弧度

lv_style_set_bg_opa(&style, LV_OPA_80); // 设置样式背景的透明度,不透明

color.full = 0xFF020D10;

lv_style_set_bg_color(&style, color);

color.full = 0xFFffffff;

lv_style_set_border_color(&style, color); // 设置样式边框颜色为黑色

lv_style_set_border_width(&style, 3); // 设置边框宽度

lv_style_set_border_opa(&style, LV_OPA_100);  // 设置边框透明度

lv_style_set_border_side(&style, LV_BORDER_SIDE_FULL);



obj_bg = obj = lv_obj_create(obj);

lv_obj_add_style(obj, &style, 0); // 给对象添加样式

lv_obj_set_size(obj, 600, 340);

lv_obj_center(obj);

lv_obj_set_scrollbar_mode(obj_bg, LV_SCROLLBAR_MODE_OFF);

lv_obj_clear_flag(obj_bg,LV_OBJ_FLAG_SCROLLABLE);

text_color.full = 0xffffffff;

obj = lv_label_create(obj_bg);



lv_obj_set_style_text_font(obj, &lv_font_montserrat_28, 0);

lv_obj_set_size(obj, 600, 100);

lv_label_set_long_mode(obj, LV_LABEL_LONG_WRAP);

lv_obj_set_style_text_align(obj,LV_TEXT_ALIGN_CENTER,0);

lv_obj_set_style_text_color(obj, text_color, 0);

lv_obj_align(obj, LV_ALIGN_CENTER, 0, -20);

lv_label_set_text(obj, text_2);

obj = lv_btn_create(obj_bg);

lv_obj_set_style_bg_color(obj,lv_palette_main(LV_PALETTE_BLUE),LV_STATE_PRESSED);

lv_obj_set_style_bg_color(obj,color,LV_STATE_DEFAULT);

lv_obj_add_event_cb(obj, event_cb_2, LV_EVENT_CLICKED, (void *)0);

lv_obj_set_size(obj, 220, 60);

lv_obj_align(obj, LV_ALIGN_LEFT_MID, 10, 120);

obj = lv_label_create(obj);

lv_obj_set_style_text_font(obj, &lv_font_montserrat_28, 0);

text_color.full = 0xff313131;

lv_obj_set_style_text_color(obj, text_color, 0);

if(SystemConfig::GetInstance()->GetSystemConfig(SYSTEM_CONFIG_SYSTEM_LANGUAGE) == 6)

{

    lv_obj_align(obj, LV_ALIGN_CENTER, 0, 12);

}else{

    lv_obj_align(obj, LV_ALIGN_CENTER, 0, 0);

}

lv_label_set_text(obj, Font::GetStr(RES_STR_SETTINGS_BOX_OK));

obj = lv_btn_create(obj_bg);

lv_obj_set_style_bg_color(obj,lv_palette_main(LV_PALETTE_BLUE),LV_STATE_PRESSED);

lv_obj_set_style_bg_color(obj,color,LV_STATE_DEFAULT);

lv_obj_add_event_cb(obj, event_cb_1, LV_EVENT_CLICKED, (void *)0);

lv_obj_set_size(obj, 220, 60);

lv_obj_align(obj, LV_ALIGN_RIGHT_MID, -10, 120);

obj = lv_label_create(obj);

lv_obj_set_style_text_font(obj, &lv_font_montserrat_28, 0);

text_color.full = 0xff313131;

lv_obj_set_style_text_color(obj, text_color, 0);

if(SystemConfig::GetInstance()->GetSystemConfig(SYSTEM_CONFIG_SYSTEM_LANGUAGE) == 6)

{

    lv_obj_align(obj, LV_ALIGN_CENTER, 0, 12);

}else{

    lv_obj_align(obj, LV_ALIGN_CENTER, 0, 0);

}

lv_label_set_text(obj, Font::GetStr(RES_STR_SETTINGS_BOX_CANCEL));

}

void Prompt::DeleteDialogBox()

{

if (obj_dialog)

{

    pthread_mutex_lock(&lock);

    lv_obj_del_async(obj_dialog);

    obj_dialog = NULL;

    pthread_mutex_unlock(&lock);

}

}
以上是代码
Thread 1 “cvr_app” received signal SIGSEGV, Segmentation fault.
0xa6b5d278 in _lv_event_mark_deleted () from /usr/lib/liblvgl.so
这个是报错信息

应该有一个锁用在维持 lvgl 心跳和删除对象操作之间(不同线程)。也就是执行删除操作和lvgl心跳维持是互斥的。还有一些其他注意点,你可以阅读这里的文档了解: http://lvgl.100ask.net/8.2/porting/os.html?highlight=%E7%BA%BF%E7%A8%8B#tasks-and-threads

看了下,好像没有太明白,有没有相关案例,参考一下,谢谢啦

这个没有使用多线程

请问一下这个问题有后续吗,是怎么解决的?

del对象之前,先 lv_obj_remove_event_cb 看看

我在使用lvgl 8.3时同样遇到该问题。在调试中发现_lv_event_mark_deleted函数中
while(e){//此处问题,结构体有指向的地址,但成员为空
if(e->current_target == obj || e->target == obj) e->deleted = 1;
e = e->prev;
}
在判断e是否为空时出错,修改代码为while(!(((lv_obj_t *)e) == e))即可。判断结构体地址是否与第一个成员地址一致,若一致则结构体为空。

大佬帮看看我的贴子,我在使用LVGL8.3模拟器开发时,使用lv_obj_clean()出现卡死,没有使用多线程,lvgl界面处理和lv_timer_handler放在同一个线程中

尝试在界面刷新函数中添加互斥锁,若不行,通过调试查看问题所在

如下所示:

while(1) {
      /* Periodically call the lv_task handler.
       * It could be done in a timer interrupt or an OS task too.*/
      page_massage_handle(5);
      lv_timer_handler();
      usleep(5 * 1000);
  }

我的页面处理是放在lv_timer_handle()前面,属于上下文关系,是要执行完我的页面刷新函数才能执行lv_timer_handler(),理论上已经是互斥了,但是还是出现卡死问题

请问该问题有没有解决方法?我也遇到了同样的问题!