segmentation fault on pressing button

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

segmentation fault on pressing button

85 次查看
sana
Contributor II

Hi,
I am using imx9352 processor and upon clicking one of the eco button from my menu page i am loading eco screen along with creating text areas at run time to use single key board.
Whenever user clicks this button seg fault is coming and screen is turning blank what could be the reason .

void screen_init(lv_obj_t *parent)
{

    ta_best_load_ratio_val_1 = lv_textarea_create(guider_ui.ECO_page_container_eco_page_cont);
    lv_obj_set_pos(ta_best_load_ratio_val_1, 279134);  
    lv_obj_set_size(ta_best_load_ratio_val_1, 10430);  
    lv_obj_set_style_bg_color(ta_best_load_ratio_val_1, lv_color_hex(0xE8E8E8), 0);
    lv_obj_set_style_text_font(ta_best_load_ratio_val_1, &lv_font_NotoSans_Regular_18, 0);
    lv_obj_add_event_cb(ta_best_load_ratio_val_1, ta_focus_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_best_load_ratio_val_1, ta_done_cb,  LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_best_load_ratio_val_1, textarea_event_cb, LV_EVENT_ALL, NULL);
    lv_obj_clear_flag(ta_best_load_ratio_val_1, LV_OBJ_FLAG_SCROLLABLE);
    lv_textarea_set_cursor_pos(ta_best_load_ratio_val_1, -1);  
    lv_textarea_set_one_line(ta_best_load_ratio_val_1, true);

 
    ta_eco_cycle_period_val_1 = lv_textarea_create(guider_ui.ECO_page_container_eco_page_cont);
    lv_obj_set_pos(ta_eco_cycle_period_val_1, 279180);
    lv_obj_set_size(ta_eco_cycle_period_val_1, 10430);  
    lv_obj_set_style_bg_color(ta_eco_cycle_period_val_1, lv_color_hex(0xD8D8D8), 0);
    lv_obj_set_style_text_font(ta_eco_cycle_period_val_1, &lv_font_NotoSans_Regular_18, 0);
    lv_obj_add_event_cb(ta_eco_cycle_period_val_1, ta_focus_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_eco_cycle_period_val_1, ta_done_cb,  LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_eco_cycle_period_val_1, textarea_event_cb, LV_EVENT_ALL, NULL);
    lv_obj_clear_flag(ta_eco_cycle_period_val_1, LV_OBJ_FLAG_SCROLLABLE);
    lv_textarea_set_cursor_pos(ta_eco_cycle_period_val_1, -1);
    lv_textarea_set_one_line(ta_eco_cycle_period_val_1, true);

    ta_eco_min_module_no_val_1 = lv_textarea_create(guider_ui.ECO_page_container_eco_page_cont);
    lv_obj_set_pos(ta_eco_min_module_no_val_1, 69388);
    lv_obj_set_size(ta_eco_min_module_no_val_1, 10430);  
    lv_obj_set_style_bg_color(ta_eco_min_module_no_val_1, lv_color_hex(0xD8D8D8), 0);
    lv_obj_set_style_text_font(ta_eco_min_module_no_val_1, &lv_font_NotoSans_Regular_18, 0);
    lv_obj_add_event_cb(ta_eco_min_module_no_val_1, ta_focus_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_eco_min_module_no_val_1, ta_done_cb,  LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_eco_min_module_no_val_1, textarea_event_cb, LV_EVENT_ALL, NULL);
    lv_obj_clear_flag(ta_eco_min_module_no_val_1, LV_OBJ_FLAG_SCROLLABLE);
    lv_textarea_set_cursor_pos(ta_eco_min_module_no_val_1, -1);
    lv_textarea_set_one_line(ta_eco_min_module_no_val_1, true);

    ta_rect_save_stop_val_1 = lv_textarea_create(guider_ui.ECO_page_container_eco_page_cont);
    lv_obj_set_pos(ta_rect_save_stop_val_1, 693134);
    lv_obj_set_size(ta_rect_save_stop_val_1, 10430);  
    lv_obj_set_style_bg_color(ta_rect_save_stop_val_1, lv_color_hex(0xE8E8E8), 0);
    lv_obj_set_style_text_font(ta_rect_save_stop_val_1, &lv_font_NotoSans_Regular_18, 0);
    lv_obj_add_event_cb(ta_rect_save_stop_val_1, ta_focus_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_rect_save_stop_val_1, ta_done_cb,  LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_rect_save_stop_val_1, textarea_event_cb, LV_EVENT_ALL, NULL);
    lv_obj_clear_flag(ta_rect_save_stop_val_1, LV_OBJ_FLAG_SCROLLABLE);
    lv_textarea_set_cursor_pos(ta_rect_save_stop_val_1, -1);
    lv_textarea_set_one_line(ta_rect_save_stop_val_1, true);

    ta_dry_time_val_1 = lv_textarea_create(guider_ui.ECO_page_container_eco_page_cont);
    lv_obj_set_pos(ta_dry_time_val_1, 693180);
    lv_obj_set_size(ta_dry_time_val_1, 10430);  
    lv_obj_set_style_bg_color(ta_dry_time_val_1, lv_color_hex(0xD8D8D8), 0);
    lv_obj_set_style_text_font(ta_dry_time_val_1, &lv_font_NotoSans_Regular_18, 0);
    lv_obj_add_event_cb(ta_dry_time_val_1, ta_focus_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_dry_time_val_1, ta_done_cb,  LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_dry_time_val_1, textarea_event_cb, LV_EVENT_ALL, NULL);
    lv_obj_clear_flag(ta_dry_time_val_1, LV_OBJ_FLAG_SCROLLABLE);
    lv_textarea_set_cursor_pos(ta_dry_time_val_1, -1);
    lv_textarea_set_one_line(ta_dry_time_val_1, true);

    ta_best_load_ratio_val_2 = lv_textarea_create(guider_ui.ECO_page_container_eco_page_cont);
    lv_obj_set_pos(ta_best_load_ratio_val_2, 279303);  
    lv_obj_set_size(ta_best_load_ratio_val_2, 10430);  
    lv_obj_set_style_bg_color(ta_best_load_ratio_val_2, lv_color_hex(0xE8E8E8), 0);
    lv_obj_set_style_text_font(ta_best_load_ratio_val_2, &lv_font_NotoSans_Regular_18, 0);
    lv_obj_add_event_cb(ta_best_load_ratio_val_2, ta_focus_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_best_load_ratio_val_2, ta_done_cb,  LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_best_load_ratio_val_2, textarea_event_cb, LV_EVENT_ALL, NULL);
    lv_obj_clear_flag(ta_best_load_ratio_val_2, LV_OBJ_FLAG_SCROLLABLE);
    lv_textarea_set_cursor_pos(ta_best_load_ratio_val_2, -1);
    lv_textarea_set_one_line(ta_best_load_ratio_val_2, true);

 
    ta_eco_cycle_period_val_2 = lv_textarea_create(guider_ui.ECO_page_container_eco_page_cont);
    lv_obj_set_pos(ta_eco_cycle_period_val_2, 279349);
    lv_obj_set_size(ta_eco_cycle_period_val_2, 10430);  
    lv_obj_set_style_bg_color(ta_eco_cycle_period_val_2, lv_color_hex(0xD8D8D8), 0);
    lv_obj_set_style_text_font(ta_eco_cycle_period_val_2, &lv_font_NotoSans_Regular_18, 0);
    lv_obj_add_event_cb(ta_eco_cycle_period_val_2, ta_focus_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_eco_cycle_period_val_2, ta_done_cb,  LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_eco_cycle_period_val_2, textarea_event_cb, LV_EVENT_ALL, NULL);
    lv_obj_clear_flag(ta_eco_cycle_period_val_2, LV_OBJ_FLAG_SCROLLABLE);
    lv_textarea_set_cursor_pos(ta_eco_cycle_period_val_2, -1);
    lv_textarea_set_one_line(ta_eco_cycle_period_val_2, true);

    ta_eco_min_module_no_val_2 = lv_textarea_create(guider_ui.ECO_page_container_eco_page_cont);
    lv_obj_set_pos(ta_eco_min_module_no_val_2, 693257);
    lv_obj_set_size(ta_eco_min_module_no_val_2, 10430);  
    lv_obj_set_style_bg_color(ta_eco_min_module_no_val_2, lv_color_hex(0xD8D8D8), 0);
    lv_obj_set_style_text_font(ta_eco_min_module_no_val_2, &lv_font_NotoSans_Regular_18, 0);
    lv_obj_add_event_cb(ta_eco_min_module_no_val_2, ta_focus_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_eco_min_module_no_val_2, ta_done_cb,  LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_eco_min_module_no_val_2, textarea_event_cb, LV_EVENT_ALL, NULL);
    lv_obj_clear_flag(ta_eco_min_module_no_val_2, LV_OBJ_FLAG_SCROLLABLE);
    lv_textarea_set_one_line(ta_eco_min_module_no_val_2, true);
    lv_textarea_set_max_length(ta_eco_min_module_no_val_2, 5);
    lv_textarea_set_cursor_pos(ta_eco_min_module_no_val_2, -1);

    ta_dcdc_save_stop_val_2 = lv_textarea_create(guider_ui.ECO_page_container_eco_page_cont);
    lv_obj_set_pos(ta_dcdc_save_stop_val_2, 693303);
    lv_obj_set_size(ta_dcdc_save_stop_val_2, 10430);  
    lv_obj_set_style_bg_color(ta_dcdc_save_stop_val_2, lv_color_hex(0xE8E8E8), 0);
    lv_obj_set_style_text_font(ta_dcdc_save_stop_val_2, &lv_font_NotoSans_Regular_18, 0);
    lv_obj_add_event_cb(ta_dcdc_save_stop_val_2, ta_focus_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_dcdc_save_stop_val_2, ta_done_cb,  LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_dcdc_save_stop_val_2, textarea_event_cb, LV_EVENT_ALL, NULL);
    lv_textarea_set_one_line(ta_dcdc_save_stop_val_2, true);
    lv_obj_clear_flag(ta_dcdc_save_stop_val_2, LV_OBJ_FLAG_SCROLLABLE);
    lv_textarea_set_cursor_pos(ta_dcdc_save_stop_val_2, -1);

    ta_dry_time_val_2 = lv_textarea_create(guider_ui.ECO_page_container_eco_page_cont);
    lv_obj_set_pos(ta_dry_time_val_2, 693349);
    lv_obj_set_size(ta_dry_time_val_2, 10430);  
    lv_obj_set_style_bg_color(ta_dry_time_val_2, lv_color_hex(0xD8D8D8), 0);
    lv_obj_set_style_text_font(ta_dry_time_val_2, &lv_font_NotoSans_Regular_18, 0);
    lv_obj_add_event_cb(ta_dry_time_val_2, ta_focus_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_dry_time_val_2, ta_done_cb,  LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_dry_time_val_2, textarea_event_cb, LV_EVENT_ALL, NULL);
    lv_textarea_set_one_line(ta_dry_time_val_2, true);
    lv_obj_clear_flag(ta_dry_time_val_2, LV_OBJ_FLAG_SCROLLABLE);
    lv_textarea_set_cursor_pos(ta_dry_time_val_2, -1);

    ta_ipv4_addr = lv_textarea_create(guider_ui.network_setting_page_network_setting_cont);
    lv_obj_set_pos(ta_ipv4_addr, 234105);     // adjust position
    lv_obj_set_size(ta_ipv4_addr, 20030);     // adjust size
    lv_obj_set_style_bg_color(ta_ipv4_addr, lv_color_hex(0xE8E8E8), 0);
    lv_obj_set_style_text_font(ta_ipv4_addr, &lv_font_NotoSans_Regular_18, 0);
    lv_textarea_set_placeholder_text(ta_ipv4_addr, "IPv4 Address");
    lv_obj_add_event_cb(ta_ipv4_addr, ta_focus_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_ipv4_addr, ta_done_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_ipv4_addr, textarea_event_cb, LV_EVENT_ALL, NULL);
    lv_obj_clear_flag(ta_ipv4_addr, LV_OBJ_FLAG_SCROLLABLE);
    lv_textarea_set_cursor_pos(ta_ipv4_addr, -1);
    lv_textarea_set_one_line(ta_ipv4_addr, true);

        // IPv4 Subnet Mask
    ta_ipv4_mask = lv_textarea_create(guider_ui.network_setting_page_network_setting_cont);
    lv_obj_set_pos(ta_ipv4_mask, 234152);
    lv_obj_set_size(ta_ipv4_mask, 20030);
    lv_obj_set_style_bg_color(ta_ipv4_mask, lv_color_hex(0xD8D8D8), 0);
    lv_obj_set_style_text_font(ta_ipv4_mask, &lv_font_NotoSans_Regular_18, 0);
    lv_textarea_set_placeholder_text(ta_ipv4_mask, "Subnet Mask");
    lv_obj_add_event_cb(ta_ipv4_mask, ta_focus_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_ipv4_mask, ta_done_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_ipv4_mask, textarea_event_cb, LV_EVENT_ALL, NULL);
    lv_obj_clear_flag(ta_ipv4_mask, LV_OBJ_FLAG_SCROLLABLE);
    lv_textarea_set_cursor_pos(ta_ipv4_mask, -1);
    lv_textarea_set_one_line(ta_ipv4_mask, true);

    // IPv4 Gateway
    ta_ipv4_gw = lv_textarea_create(guider_ui.network_setting_page_network_setting_cont);
    lv_obj_set_pos(ta_ipv4_gw, 234199);
    lv_obj_set_size(ta_ipv4_gw, 20030);
    lv_obj_set_style_bg_color(ta_ipv4_gw, lv_color_hex(0xE8E8E8), 0);
    lv_obj_set_style_text_font(ta_ipv4_gw, &lv_font_NotoSans_Regular_18, 0);
    lv_textarea_set_placeholder_text(ta_ipv4_gw, "Gateway");
    lv_obj_add_event_cb(ta_ipv4_gw, ta_focus_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_ipv4_gw, ta_done_cb, LV_EVENT_ALL, NULL);
    lv_obj_add_event_cb(ta_ipv4_gw, textarea_event_cb, LV_EVENT_ALL, NULL);
    lv_obj_clear_flag(ta_ipv4_gw, LV_OBJ_FLAG_SCROLLABLE);
    lv_textarea_set_cursor_pos(ta_ipv4_gw, -1);
    lv_textarea_set_one_line(ta_ipv4_gw, true);

    /* 1) Create one keyboard */
    kb = lv_keyboard_create(parent);
    lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
    lv_obj_set_size(kb, LV_PCT(100), LV_PCT(40));
    // lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_TEXT_LOWER);
    lv_obj_align(kb, LV_ALIGN_BOTTOM_MID, 00);
    // lv_keyboard_set_cursor_manage(kb, true);

}
this i am calling at event handler as 
static void menu_page_eco_btn_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_CLICKED:
    {
        ui_load_scr_animation(&guider_ui&guider_ui.ECO_page_containerguider_ui.ECO_page_container_del&guider_ui.menu_page_delsetup_scr_ECO_page_container, LV_SCR_LOAD_ANIM_FADE_ON, 200200truefalse);

        create_alarm_bar(guider_ui.ECO_page_container_eco_page_cont);


        // Ensure it's visible when Overview page is loaded
        lv_obj_clear_flag(alarm_bar, LV_OBJ_FLAG_HIDDEN);
        screen_init(guider_ui.ECO_page_container);
        break;
    }
    default:
        break;
    }
}
and i am including free memory of current screen so in the backend a thread in which a client is trying to update values to the above created text areas will be running when this backend is including at that time only seg fault is coming but upon clicking just frontend without any backend which access text areas by creating upon clicking eco btn no seg fault is noticed.
Is there any specific method of accessing textareas created by above init function in click event handler.
Also the LcdHandler_Init(); function for text areas updating is being called at 
int main(void)
{
    /* Initialize LVGL */
    lv_init();

    /* Initialize the HAL (display, input devices) for LVGL */
    hal_init();

    /* Create a GUI-Guider app */
    setup_ui(&guider_ui);
    events_init(&guider_ui);
    custom_init(&guider_ui);
    // Initialize the LCD handler and DBus connection
    LcdHandler_Init();
#if LV_USE_VIDEO
     pthread_create(&video_thread, NULL, videoPlayThread, NULL);
#endif

    /* Handle LVGL tasks */
#if LV_USE_WAYLAND
    bool completed;

    while (1) {
        completed = lv_wayland_timer_handler();

        if (completed) {
            /* wait only if the cycle was completed */
            usleep(LV_DEF_REFR_PERIOD * 1000);
        }

        /* Run until the last window closes */
        if (!lv_wayland_window_is_open(NULL)) {
            break;
        }
    }
#else
    uint32_t idle_time;

    while(1) {
        /* Return the time to the next timer execution */
        idle_time = lv_timer_handler();
    usleep(idle_time * 1000);
    }
#endif

    return 0;
}
Also the memory size we allocated is 1535998 kb
Please look into meta layer where custom files are being added
please reach out with quick response as soon as possible.
It's very critical team,
0 项奖励
回复
2 回复数

38 次查看
Manuel_Salas
NXP TechSupport
NXP TechSupport

Hello @sana 

I hope you are doing very well.

 

All LVGL object creation, deletion, or modification must happen from the same thread that runs lv_timer_handler(), and in your code, you spawn a backend thread (LcdHandler_Init) which tries to directly update ta_* objects.

That means LVGL objects are being touched from two threads:

1. UI loop (main thread running lv_timer_handler())

2. Your back-end thread

 

When you press the ECO button it crash because that is where you dynamically create new textareas.

The backend thread probably has a pointer to one of them and is updating it while LVGL is still laying it out or freeing old ones. The memory behind the lv_obj_t * becomes invalid.

 

You can try using lv_async_call().

 

It should be very helpful if you can share your Gui Guider project and Gui guider version.

 

Best regards,

Salas.

0 项奖励
回复

3 次查看
sana
Contributor II
Yeah we tried using lv_async_call()
It did cleared seg fault.
Thanks team
0 项奖励
回复