No screen found when closing message box

What do you want to achieve?

I have a message box that pops up when a warning needs to be shown to the user. The vast majority of the time when I click the Okay button it closes but sometime I get the following error:

[Warn]  (8274.980, +180)         lv_obj_get_disp: No screen found       (in lv_obj_tree.c line #286)

The message box does not close and if I keep clicking on the Okay button, I keep getting this error.
My message box code looks like:

/**
 * @brief Displays a warning popup to the user.
 * 
 * @param msg The warning message to be displayed.
 */
void ShowWarningMessageBox( const char *msg )
{
    static const char * btns[] ={ "Okay", "" };

    _warningMessageBox = lv_msgbox_create( NULL, "Warning", msg, btns, false );
    lv_obj_add_event_cb( _warningMessageBox, OnWarningMessageBoxCloseEventHandler, LV_EVENT_VALUE_CHANGED, NULL );
    lv_obj_set_style_bg_color( _warningMessageBox, lv_palette_main( LV_PALETTE_BLUE_GREY ), LV_PART_MAIN );
    lv_obj_set_style_text_font( _warningMessageBox, &ui_font_Robinson32, LV_PART_MAIN );

    lv_obj_t *btn = lv_msgbox_get_btns( _warningMessageBox );
    const lv_font_t *font = lv_obj_get_style_text_font( btn, LV_PART_ITEMS );
    lv_coord_t btn_h = lv_font_get_line_height( font ) + 130 / 10;
    lv_obj_set_size( btn, 2/*2 buttons*/ * ( 2 * 130 / 3 ), btn_h );

    lv_obj_set_width( _warningMessageBox, 500 );
    lv_obj_set_height( _warningMessageBox, 200 );
    lv_obj_center( _warningMessageBox );
}

/**
 * @brief The callback when the user clicks Okay on the message box.
 * 
 * This event handler is used to clear the message box from the screen.
 * 
 * @param e The button that was clicked on the message box.
 */
static void OnWarningMessageBoxCloseEventHandler( lv_event_t * e )
{
    lv_obj_t * obj = lv_event_get_current_target( e );
    lv_msgbox_close( _warningMessageBox );
}

Any thoughts on what I might be doing wrong?

What have you tried so far?

N/A

Screenshot or video

N/A

Others

  • SquareLine Studio version:
    1.0.5
  • Operating system:
    Windows 10 x64
  • Target hardware:
    Raspberry Pi 4

Your code looks good, and I can’t see the warning.

Can you add a breakpoint to lv_obj_tree.c line #286 and send a screenshot about the callstack?

You can also enable all LV_USE_ASSERT_*s in lv_conf.h. They usually help to spot the problems earlier.

Will do - will report back when it next happens.

Andy