Fixed bug 1897 - CPU spike on Windows with WM_EVENT and OpenGL
authorSam Lantinga <slouken@libsdl.org>
Thu, 06 Jun 2013 23:18:36 -0700
changeset 7295737cc5bad795
parent 7294 0923de98a63a
child 7296 a8145f734ad3
Fixed bug 1897 - CPU spike on Windows with WM_EVENT and OpenGL

buckyballreaction

On some Windows systems, when switching from fullscreen to windowed mode in my game, the CPU will spike and the application never shows the window again.

See the part of the e-mail thread here:

http://lists.libsdl.org/pipermail/sdl-libsdl.org/2013-June/088626.html

I change the window by calling:

SDL_SetWindowFullscreen(gScreenInfo.sdlWindow, SDL_FALSE);
SDL_SetWindowSize(gScreenInfo.sdlWindow, sdlWindowWidth, sdlWindowHeight);

which you can see in our source:

https://code.google.com/p/bitfighter/source/browse/zap/VideoSystem.cpp#377

Then all of a sudden the application gets stuck in WIN_PumpEvents() in SDL_windowsevents.c. I turned on WMMSG_DEBUG and found that there was an endless stream of WM_EVENT messages. I also found that where WM_PAINT is being handled in the callback WIN_WindowProc(), ValidateRect is somehow not clearing, or it is persisting, the WM_EVENT message like it's supposed to (according to the docs).

This may be a hardware issue. The issue has appeared on three different systems, one of them sporadically:
- Windows XP SP3 running in VMware 9.0 (without VMWare 3D acceleration, but with the tools and drivers installed), Host: openSUSE 12.3 x86_64, NVidia NVS 3100M
- Windows XP SP3 64bit running in VirtualBox, Host: Debian Wheezy (stable), Mobility Radeon HD 4100 (this was the sporadic one)
- Windows 7 64 bit, Radeon 6770
src/video/windows/SDL_windowsevents.c
     1.1 --- a/src/video/windows/SDL_windowsevents.c	Thu Jun 06 18:20:06 2013 -0700
     1.2 +++ b/src/video/windows/SDL_windowsevents.c	Thu Jun 06 23:18:36 2013 -0700
     1.3 @@ -644,7 +644,7 @@
     1.4          {
     1.5              RECT rect;
     1.6              if (GetUpdateRect(hwnd, &rect, FALSE)) {
     1.7 -                ValidateRect(hwnd, &rect);
     1.8 +                ValidateRect(hwnd, NULL);
     1.9                  SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED,
    1.10                                      0, 0);
    1.11              }