https://bugs.winehq.org/show_bug.cgi?id=38394
--- Comment #3 from Stefan Dösinger stefan@codeweavers.com --- Created attachment 51256 --> https://bugs.winehq.org/attachment.cgi?id=51256 Don't pump messages on mode changes
Can you give this patch a try? It fixes the crash for me, but it has some pretty bad problems.
Some details: message 0xc045 is a message internal to the application. It is in the message queue, sent by a different application thread, when the focus loss message is processed. During the focus loss handling wined3d calls ChangeDisplaySettingsEx, and winex11 eventually calls SendMessage(WM_X11DRV_RESIZE_DESKTOP). This sendmessage call (correctly) processes other messages in the message queue, so the application processes it's internal 0xc045 message while wined3d is in the focus loss handling code. The application destroys the ddraw object, and the wined3d code crashes.
Native ddraw also crashes if the ddraw object is destroyed during focus loss. However, ChangeDisplaySettings[Ex] is not supposed to pump messages according to my testing, though I still have to write a formal test for this.
Now the problem with the attached patch is that it delays mode changes by a few seconds when not using a virtual desktop. The cause for this is that nobody listens to messages on GetDesktopWindow() in this case, causing the SendMessageTimeoutW call to time out. When using SendMessage (or SendMessageTimeoutW without SMTO_BLOCK) the SendMessage call succeeds instantly, although I don't yet understand why, and WM_X11DRV_RESIZE_DESKTOP is never processed by X11DRV_WindowMessage.