Local_border_color of an msgbox


I try to change the local_border_color of btns in an msgbox. but when I try to do this by:

lv_obj_set_style_local_border_color(msgbox_confirmation, LV_MSGBOX_PART_BTN, LV_STATE_DEFAULT, LV_COLOR_RED);

I get a hard fault. Not sure but it seems a bug to me. So I would appreciate it if someone checks this and let me know if it is.

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

stm32f429, GCC, cubeide

What LVGL version are you using?


What do you want to achieve?

try to change the local_border_color of btns in a msgbox

What have you tried so far?

using this code:

lv_obj_set_style_local_border_color(msgbox_confirmation, LV_MSGBOX_PART_BTN, LV_STATE_DEFAULT, LV_COLOR_RED);

Hmm, it seems to work for me on STM32F7 (using v7). It might be worth double checking that msgbox_confirmation is not NULL?

1 Like

No it’s not. because I can change other style features like:

lv_obj_set_style_local_text_font(msgbox_confirmation, LV_MSGBOX_PART_BG, LV_STATE_DEFAULT, &lv_font_montserrat_22);

This works as expected in the simulator. Can you provide a back trace from the hard fault?

1 Like

Make sure you call lv_msgbox_add_btns before you add any styles to LV_MSGBOX_PART_BTN. This works in the simulator:

    static const char * btns[] ={"OK", ""};
    lv_obj_t * msgbox_confirmation = lv_msgbox_create(lv_scr_act(), NULL);

    lv_msgbox_add_btns(msgbox_confirmation, btns);
    lv_obj_set_style_local_border_color(msgbox_confirmation, LV_MSGBOX_PART_BTN, LV_STATE_DEFAULT, LV_COLOR_RED);

If I swap lines 3 and 4, it faults.

1 Like

dear @embeddedt @jupeos thanks for your help.
and yes dear @egonbeermat your guess was right. It’s working now. thanks.

1 Like

@embeddedt @kisvegabor
Not sure if this problem can be avoided by code but if it can’t I think it should be declared in the documentation.
what do you think?

I agree with updating the documentation.

For v7, we could add a condition somewhere in the style code to prevent dereferencing a null style list, but the operation will still be a no-op, which isn’t really any better and could be even harder to debug.

The issue is that the button matrix which the styles are stored on doesn’t get created until lv_msgbox_add_btns is called. My guess is that this was implemented as a memory-saving measure for the case where a message box is created without buttons.

In v8 it looks like the button matrix is always created so this won’t be an issue.

1 Like

I’ve just added a note to the v7 docs for this.

1 Like