Description
Crash when using message box with button matrix.
What MCU/Processor/Board and compiler are you using?
PlatformIO simulator on Linux
What LVGL version are you using?
7.9.1
What do you want to achieve?
I want to use a message box with buttons.
What have you tried so far?
I’m running this code in the simulator on Linux platform using my SDL based encoder driver.
When I click the “Yes” button:
lv_msgbox_get_active_btn function returns id 0, that is correct, but lv_msgbox_get_active_btn_text() returns NULL, because ext->btn_id_act = 0xFFFF (lv_btnmatrix.c:504)
When I click the “Cancel” button everything works as expected.
If I add a dummy button at the beginning, like
static const char *exitMsgButtons[] = {"dummy", "Yes", "Cancel", ""};
“Yes” and “Cancel” work as expected, but “dummy” fails, because of the wrong ID.
Code to reproduce
// Global array of button labels.
static const char *exitMsgButtons[] = {"Yes", "Cancel", ""};
// Message box event handler.
static void exit_msgbox_event_handler(lv_obj_t *obj, lv_event_t event)
{
if (LV_EVENT_VALUE_CHANGED == event) {
uint16_t id = lv_msgbox_get_active_btn(obj);
const char *btext = lv_msgbox_get_active_btn_text(obj);
if (0 == strcmp(exitMsgButtons[0], btext)) {
lv_obj_clean(lv_scr_act());
printf("Simulator Power OFF\n");
} else if (0 == strcmp(exitMsgButtons[1], btext)) {
printf("Simulator exit cancelled\n");
} else {
;
}
lv_obj_del(obj);
}
}
// Function that creates the message box.
void SensorioConfirmExit(void)
{
lv_obj_t *mbox = lv_msgbox_create(lv_scr_act(), NULL);
lv_msgbox_set_text(mbox, "Do you want to exit?");
lv_msgbox_add_btns(mbox, exitMsgButtons);
lv_obj_set_width(mbox, 200);
lv_obj_set_event_cb(mbox, exit_msgbox_event_handler);
lv_obj_align(mbox, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
lv_group_remove_all_objs(encgroup);
lv_group_add_obj(encgroup, mbox);
}
Since I’m totally new to LVGL, I might be doing something wrong. Could you help me which direction to go on?
Thanks a lot!
Zoltan