crash: start in fullscreen, change to a window, close the game.
This is sort of trial-and-error: there seems to be no documentation about
the proper order of shutting down a window. Shutting down D3D first
makes sense: restore the window to normal, then destroy it, so we don't
kill the window while D3D is still using it. But this seems to work, and
it's how we did it in 3.9.
(I think releasing D3D first is leaving traces behind in the window, which
then cause stale dereferences; the previous FreeLibrary() change was for
the same problem, and this seems to just be another incarnation of that.)
7c918fea: ntdll!RtlpWaitForCriticalSection [7c900000+18f8f+5b]
77d48bd9: USER32!GetWindowThreadProcessId [77d40000+8a80+159]
77d4b3cc: USER32!DefWindowProcW [77d40000+b33c+90]
7c90104b: ntdll!RtlEnterCriticalSection [7c900000+1005+46]
6d9ab228: D3D8!CheckFullscreen [6d9a0000+b060+1c8]
77d48734: USER32!GetDC [77d40000+86c7+6d]
77d4b4c0: USER32!DefWindowProcW [77d40000+b33c+184]
7c90eae3: ntdll!KiUserCallbackDispatcher [7c900000+ead0+13]
77d4daf6: USER32!DestroyWindow [77d40000+daea+c]
00539971: void GraphicsWindow::DestroyGraphicsWindow(void) [00400000+1398d1+a0]
is usually 640x480, and we shifted by -0.5x-0.5 there. That works for 640x480,
but is incorrect for other resolutions. Do this in projection space, just like
the centering matrix.
An easy way to test this is to set 1280x960 (2x resolution), create a 1280x960
texture, and display it fullscreen in-game. Just like at 640x480 with a 640x480
graphic, the texture should be displayed pixel-for-pixel identically to the source
(when in 32-bit).
we were in when we lost the device, not do a complete mode search
from scratch. This fixes a dependency on the behavior of storing
the last successful mode change back into PREFSMAN. (This is
D3D's equivalent to the WM_ACTIVATE -> ChangeDisplaySettings code
in GraphicsWindow.)
D3D has the best response to these reference leaks ever: on shutdown, some
part of window closing or screen mode resetting will freeze for about five seconds,
depending on the window mode. No indication why is given.