Hardfault - Text, In Cont, In page, setFocus provoc hardfault


  • i have a page that i want to scroll horizontally
  • the page contain several cont, with auto layout
  • cont contain 2 labels each

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


What do you experience?

i create a page in wish i create 3 containers.
In each container i put 2 labels.
i set the embeeded container to auto fit horizontally as label size inside them can vary

to be able to scroll, i put inside cont callback function a lv_page_focus to make the item visible when selected

if i disable the horizontal autofit TIGHT the hardfault disapear.

/You code here/

if( event == LV_EVENT_FOCUSED){
		lv_page_focus(page, obj, LV_ANIM_OFF);

    // create container
	btn->cont = lv_cont_create(parent, NULL);  

	lv_cont_set_fit2(btn->cont, LV_FIT_TIGHT, LV_FIT_NONE); <<< HARDFAULT IS THIS

	lv_obj_set_style_local_bg_color(btn->cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x40, 0x40, 0x40));
	lv_obj_set_style_local_bg_color(btn->cont, LV_CONT_PART_MAIN, LV_STATE_FOCUSED, LV_COLOR_MAKE(0x00, 0x30, 0x30));

	lv_obj_set_style_local_outline_width(btn->cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
	lv_obj_set_style_local_outline_width(btn->cont, LV_CONT_PART_MAIN, LV_STATE_FOCUSED, 0);

	lv_obj_set_style_local_border_side(btn->cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_BORDER_SIDE_RIGHT);
	lv_obj_set_style_local_border_width(btn->cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 2);
	lv_obj_set_style_local_border_width(btn->cont, LV_CONT_PART_MAIN, LV_STATE_FOCUSED, 1);

	lv_obj_set_style_local_border_color(btn->cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(100, 100, 100));
	lv_obj_set_style_local_border_color(btn->cont, LV_CONT_PART_MAIN, LV_STATE_FOCUSED, LV_COLOR_MAKE(0, 150, 150));

	lv_obj_set_style_local_radius(btn->cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
	lv_obj_set_style_local_radius(btn->cont, LV_CONT_PART_MAIN, LV_STATE_FOCUSED, 0);

	lv_obj_set_style_local_outline_color(btn->cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
	lv_obj_set_style_local_outline_color(btn->cont, LV_CONT_PART_MAIN, LV_STATE_FOCUSED, LV_COLOR_BLUE);

	lv_obj_set_style_local_pad_all(btn->cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT,0);

	lv_obj_set_style_local_pad_left(btn->cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT,5);
	lv_obj_set_style_local_pad_right(btn->cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT,5);
	//lv_obj_set_style_local_pad_left(btn->cont, LV_CONT_PART_MAIN, LV_STATE_FOCUSED,8);
	//lv_obj_set_style_local_pad_right(btn->cont, LV_CONT_PART_MAIN, LV_STATE_FOCUSED,8);

	lv_obj_set_style_local_pad_top(btn->cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT,4);
	lv_obj_set_style_local_pad_bottom(btn->cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT,4);
	///lv_obj_align(btn->cont, parent, LV_ALIGN_CENTER, 0, 0);

	// create btn name label
	btn->lbl_name = lv_label_create(btn->cont, NULL);							// create label
    lv_label_set_text(btn->lbl_name, label);									// set text
    lv_obj_add_style(btn->lbl_name, LV_LABEL_PART_MAIN, &labelStyle); 			// add label style
    lv_obj_align(btn->lbl_name, btn->cont, LV_ALIGN_CENTER, 0, -12);				// align center
    lv_obj_set_style_local_text_color(btn->lbl_name, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x00, 200, 200));
    lv_obj_set_style_local_text_color(btn->lbl_name, LV_LABEL_PART_MAIN, LV_STATE_FOCUSED, LV_COLOR_MAKE(0x10, 0x10, 0x10));

    // label  value
    btn->lbl_val = lv_label_create(btn->cont, NULL);							// create
    lv_label_set_text(btn->lbl_val, "100 %");								// set temporary text
    lv_obj_add_style(btn->lbl_val, LV_LABEL_PART_MAIN, &style_labelValues);		// add style
    lv_obj_align(btn->lbl_val, btn->cont, LV_ALIGN_CENTER, 0, 20);				// align

    lv_obj_align_origo(btn->cont, page, LV_ALIGN_IN_RIGHT_MID, 0, 0);

    // callback & events
    lv_obj_set_event_cb(btn->cont, cbfunction);									// add callback function for events
    lv_group_add_obj(g, btn->cont);												// add object to group

Screenshot and/or video

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

If the container is specifically crashing when you enable autofit, it is probably this known issue. It can’t be solved in v7, but v8 introduces a new layout system which doesn’t have this problem.

I dont know how i did, but now it is not crashing anymore :slight_smile:

Autofit is still enable with my containers inside my page

Perhaps you unknowingly rearranged the objects so the problem doesn’t happen.

i just added padding style in focus state and removed borders