Skip to content

Commit 6db1852

Browse files
committed
[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.
1 parent 8e28a94 commit 6db1852

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/platforms/rcore_desktop_win32.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,11 @@ void SwapScreenBuffer(void)
14391439
LogFail("SwapBuffers", GetLastError());
14401440
abort();
14411441
}
1442+
1443+
if (!ValidateRect(global_hwnd, NULL)) {
1444+
LogFail("ValidateRect", GetLastError());
1445+
abort();
1446+
}
14421447
}
14431448

14441449
double GetTime(void)
@@ -1551,6 +1556,8 @@ void PollInputEvents(void)
15511556

15521557
MSG msg;
15531558
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
1559+
if (msg.message == WM_PAINT)
1560+
return;
15541561
TranslateMessage(&msg);
15551562
DispatchMessageW(&msg);
15561563
}
@@ -1778,12 +1785,6 @@ static LRESULT WndProc2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, Flags
17781785
}
17791786
return 0;
17801787
}
1781-
case WM_PAINT: {
1782-
PAINTSTRUCT ps;
1783-
BeginPaint(hwnd, &ps);
1784-
EndPaint(hwnd, &ps);
1785-
return 0;
1786-
}
17871788
case WM_SETCURSOR:
17881789
if (LOWORD(lparam) == HTCLIENT) {
17891790
SetCursor(CORE.Input.Mouse.cursorHidden ? NULL : LoadCursorW(NULL, IDC_ARROW));

0 commit comments

Comments
 (0)