Probably bug in win_drv.c for codeblocks

Description

In win_drv.h there’s a place where a variable might be used uninitialized, and cause errors.

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

PC simulator with codeblocks, lvgl version 7.0-dev

What do you experience?

I was sending a LV_EVENT_REFRESH to a screen, to refresh it. Then, the program aborted with 0 result. Debugging the process, I have seen that in win_drv.c a message with WM_QUIT was received. I have seen that the WM_QUIT is the same value as LV_EVENT_REFRESH (in the v7 version).

Inspecting the code, I have seen that if no message is received, the checking of the message is done, and that shouldn’t be correct.

/You code here/

This is the original code:
static void msg_handler(void *param)
{
    (void)param;

    MSG msg;
    BOOL bRet;
    if( (bRet = PeekMessage( &msg, NULL, 0, 0, TRUE )) != 0)
    {
        if (bRet == -1)
        {
            return;
        }
        else
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
        if(msg.message == WM_QUIT)
            lv_win_exit_flag = true;
}

In this code, if the PeekMessage function returns 0, the msg.message == WM_QUIT check is done, but the msg variable might be uninitialized (if the function has not changed it), which I suspect was happening to me.

I have put the checking inside the “if”, to avoid checking the msg variable if a message has not been received. It results like this

static void msg_handler(void *param)
{
    (void)param;

    MSG msg;
    BOOL bRet;
    if( (bRet = PeekMessage( &msg, NULL, 0, 0, TRUE )) != 0)
    {
        if (bRet == -1)
        {
            return;
        }
        else
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        if(msg.message == WM_QUIT)
            lv_win_exit_flag = true;
    }
}

Changing this, I don’t receive the exit message any more

Alex

I’m guilty of writing that code. :slightly_smiling_face:

Thanks for the report. It should be fixed here.

1 Like

Thank you

I just was surprised at first because the behaviour began when I upgraded ti v7, and didn’y know why. After I found that the WM_QUIT was the same as LV_EVENT_REFRESH, I suspected there there was an error somewhere.

Alex