From 6db18524b451b98d9ed5fd24282023ed415b1e28 Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Fri, 4 Apr 2025 10:50:00 -0600 Subject: [PATCH] [rcore][win32] stop lying to the OS about when our window is updated Instead of calling BeginPaint/EndPaint in WM_PAINT which signals to the OS that our window content is updated, now when we encounter the WM_PAINT message instead we return back to the raylib application which will trigger it to render a new frame. We've replaced the call to BeginPaint and EndPaint with a call to ValidateRect in SwapBuffers, which, means we're now correctly telling the OS when our window content is actually up-to-date. Note that this doesn't fix the window content not being updated during a window resize/move beacuse thos have their own message loop which doesn't return early when it's time to paint. --- src/platforms/rcore_desktop_win32.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/platforms/rcore_desktop_win32.c b/src/platforms/rcore_desktop_win32.c index f24f51e41..285a8beb6 100644 --- a/src/platforms/rcore_desktop_win32.c +++ b/src/platforms/rcore_desktop_win32.c @@ -1439,6 +1439,11 @@ void SwapScreenBuffer(void) LogFail("SwapBuffers", GetLastError()); abort(); } + + if (!ValidateRect(global_hwnd, NULL)) { + LogFail("ValidateRect", GetLastError()); + abort(); + } } double GetTime(void) @@ -1551,6 +1556,8 @@ void PollInputEvents(void) MSG msg; while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { + if (msg.message == WM_PAINT) + return; TranslateMessage(&msg); DispatchMessageW(&msg); } @@ -1778,12 +1785,6 @@ static LRESULT WndProc2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, Flags } return 0; } - case WM_PAINT: { - PAINTSTRUCT ps; - BeginPaint(hwnd, &ps); - EndPaint(hwnd, &ps); - return 0; - } case WM_SETCURSOR: if (LOWORD(lparam) == HTCLIENT) { SetCursor(CORE.Input.Mouse.cursorHidden ? NULL : LoadCursorW(NULL, IDC_ARROW));