[PATCH v4 3/3] ddraw: Restore the surface if we're the Foreground window, even if the device state is lost.

Gabriel Ivăncescu gabrielopcode at gmail.com
Tue Jul 28 09:53:57 CDT 2020


Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
 dlls/ddraw/surface.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index 8805014..c2d794b 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -3786,7 +3786,18 @@ static HRESULT WINAPI ddraw_surface7_Restore(IDirectDrawSurface7 *iface)
     }
 
     if (surface->ddraw->device_state == DDRAW_DEVICE_STATE_LOST && ddraw_surface_can_be_lost(surface))
-        return DDERR_WRONGMODE;
+    {
+        HWND window = surface->ddraw->focuswindow ? surface->ddraw->focuswindow : surface->ddraw->dest_window;
+
+        /* Railroad Tycoon 2 tries to restore the surface from within
+           a WM_QUERYNEWPALETTE message and expects it to succeed. We
+           haven't received the WM_ACTIVATEAPP message by that point,
+           so the device state is still LOST, even though we are in
+           the foreground. */
+        if (!window || GetForegroundWindow() != window) return DDERR_WRONGMODE;
+
+        surface->ddraw->device_state = DDRAW_DEVICE_STATE_NOT_RESTORED;
+    }
 
     ddraw_update_lost_surfaces(surface->ddraw);
     surface->is_lost = FALSE;
-- 
2.21.0




More information about the wine-devel mailing list