I just spent the last several hours digging through Delphi’s message-handling system, trying to find out why my SDL wrapper component wouldn’t display properly under certain circumstances. Eventually I tracked it to the fact that it was never receiving the WM_PAINT message. Turns out SDL was swallowing it to handle internally.
That’s perfectly acceptable when you have a window that SDL created and is managing, but when it’s a foreign window created by SDL_CreateWindowFrom, someone else owns the window handle and needs to be able to respond to paint requests in its own fashion.
This patch fixes it. It’s Windows only, of course. Not sure if the same problem exists on other platforms, but it wouldn’t surprise me. If so, they’ll need platform-specific fixes.
Index: SDL_win32events.c===================================================================
— SDL_win32events.c (revision 4599)
+++ SDL_win32events.c (working copy)
@@ -587,15 +587,18 @@
/* We were occluded, refresh our display */
case WM_PAINT:
-
{
-
RECT rect;
-
if (GetUpdateRect(hwnd, &rect, FALSE)) {
-
ValidateRect(hwnd, &rect);
-
SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_EXPOSED,
-
0, 0);
-
}
-
}
-
return (0);
-
{
-
if (!(SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_FOREIGN)) {
-
RECT rect;
-
if (GetUpdateRect(hwnd, &rect, FALSE)) {
-
ValidateRect(hwnd, &rect);
-
SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_EXPOSED,
-
0, 0);
-
}
-
return (0);
-
}
-
else break;
-
} /* If this isn't our window, we don't need to repaint the frame. This fixes a reentrancy issue that can cause stack overflows with foreign windows.