Paul Gofman : ddraw: Deny adding the same light to viewports multiple times.

Alexandre Julliard julliard at winehq.org
Fri Mar 22 16:06:20 CDT 2019


Module: wine
Branch: master
Commit: 9bd6b2c2bf5e7603e65215432f3a3e5dad43616c
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=9bd6b2c2bf5e7603e65215432f3a3e5dad43616c

Author: Paul Gofman <gofmanp at gmail.com>
Date:   Fri Mar 22 14:17:46 2019 +0300

ddraw: Deny adding the same light to viewports multiple times.

According to the logs attached to the bug, the application seems to
spin in endless LIST_FOR_EACH_ENTRY() in viewport_activate(), which
is the result of adding the same light structure to the list twice.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46807
Signed-off-by: Paul Gofman <gofmanp at gmail.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ddraw/tests/ddraw4.c | 27 +++++++++++++++++----------
 dlls/ddraw/viewport.c     |  7 +++++++
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index 51052fb..56ff8a6 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -4051,21 +4051,21 @@ static void test_lighting(void)
         {&mat_nonaffine, translatedquad, 0x000000ff, "Lit quad with non-affine matrix"},
     };
 
-    HWND window;
-    IDirect3D3 *d3d;
+    DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
+    IDirect3DViewport3 *viewport, *viewport2;
+    DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
+    IDirect3DMaterial3 *material;
+    D3DMATERIALHANDLE mat_handle;
     IDirect3DDevice3 *device;
     IDirectDrawSurface4 *rt;
-    IDirect3DViewport3 *viewport;
-    IDirect3DMaterial3 *material;
     IDirect3DLight *light;
-    D3DMATERIALHANDLE mat_handle;
     D3DLIGHT2 light_desc;
-    HRESULT hr;
-    DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
-    DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
+    IDirect3D3 *d3d;
     D3DCOLOR color;
     ULONG refcount;
     unsigned int i;
+    HWND window;
+    HRESULT hr;
 
     window = create_window();
     if (!(device = create_device(window, DDSCL_NORMAL)))
@@ -4160,9 +4160,16 @@ static void test_lighting(void)
     U4(light_desc.dcvColor).a = 1.0f;
     U3(light_desc.dvDirection).z = 1.0f;
     hr = IDirect3DLight_SetLight(light, (D3DLIGHT *)&light_desc);
-    ok(SUCCEEDED(hr), "Failed to set light, hr %#x.\n", hr);
+    ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
     hr = IDirect3DViewport3_AddLight(viewport, light);
-    ok(SUCCEEDED(hr), "Failed to add a light to the viewport, hr %#x.\n", hr);
+    ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+    hr = IDirect3DViewport3_AddLight(viewport, light);
+    ok(hr == D3DERR_LIGHTHASVIEWPORT, "Got unexpected hr %#x.\n", hr);
+
+    viewport2 = create_viewport(device, 0, 0, 640, 480);
+    hr = IDirect3DViewport3_AddLight(viewport2, light);
+    ok(hr == D3DERR_LIGHTHASVIEWPORT, "Got unexpected hr %#x.\n", hr);
+    IDirect3DViewport3_Release(viewport2);
 
     hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
     ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
diff --git a/dlls/ddraw/viewport.c b/dlls/ddraw/viewport.c
index 78a2fde..e7e4463 100644
--- a/dlls/ddraw/viewport.c
+++ b/dlls/ddraw/viewport.c
@@ -760,6 +760,13 @@ static HRESULT WINAPI d3d_viewport_AddLight(IDirect3DViewport3 *iface, IDirect3D
         return DDERR_INVALIDPARAMS;
     }
 
+    if (light_impl->active_viewport)
+    {
+        wined3d_mutex_unlock();
+        WARN("Light %p is active in viewport %p.\n", light_impl, light_impl->active_viewport);
+        return D3DERR_LIGHTHASVIEWPORT;
+    }
+
     /* Find a light number and update both light and viewports objects accordingly */
     while (map & 1)
     {




More information about the wine-cvs mailing list