=?UTF-8?Q?J=C3=B3zef=20Kucia=20?=: d3d9: Clamp clip plane index to valid range.

Alexandre Julliard julliard at winehq.org
Mon Dec 4 14:58:18 CST 2017


Module: wine
Branch: master
Commit: 93d45c04c4a47845acc1de4369d37f951fe2e885
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=93d45c04c4a47845acc1de4369d37f951fe2e885

Author: Józef Kucia <jkucia at codeweavers.com>
Date:   Sat Dec  2 10:24:38 2017 +0100

d3d9: Clamp clip plane index to valid range.

Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/d3d9/d3d9_private.h |  2 ++
 dlls/d3d9/device.c       | 19 ++++++++++---------
 dlls/d3d9/tests/device.c |  6 ------
 3 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index c7b67e5..7cbb540 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -97,6 +97,8 @@ struct d3d9_device
     BOOL in_scene;
     BOOL has_vertex_declaration;
 
+    unsigned int max_user_clip_planes;
+
     UINT implicit_swapchain_count;
     struct d3d9_swapchain **implicit_swapchains;
 };
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index f6086bf..655318e 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -2030,6 +2030,8 @@ static HRESULT WINAPI d3d9_device_SetClipPlane(IDirect3DDevice9Ex *iface, DWORD
 
     TRACE("iface %p, index %u, plane %p.\n", iface, index, plane);
 
+    index = min(index, device->max_user_clip_planes - 1);
+
     wined3d_mutex_lock();
     hr = wined3d_device_set_clip_plane(device->wined3d_device, index, (const struct wined3d_vec4 *)plane);
     wined3d_mutex_unlock();
@@ -2044,6 +2046,8 @@ static HRESULT WINAPI d3d9_device_GetClipPlane(IDirect3DDevice9Ex *iface, DWORD
 
     TRACE("iface %p, index %u, plane %p.\n", iface, index, plane);
 
+    index = min(index, device->max_user_clip_planes - 1);
+
     wined3d_mutex_lock();
     hr = wined3d_device_get_clip_plane(device->wined3d_device, index, (struct wined3d_vec4 *)plane);
     wined3d_mutex_unlock();
@@ -4012,7 +4016,8 @@ HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wine
         D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode)
 {
     struct wined3d_swapchain_desc *swapchain_desc;
-    UINT i, count = 1;
+    unsigned i, count = 1;
+    WINED3DCAPS caps;
     HRESULT hr;
 
     if (mode)
@@ -4025,22 +4030,18 @@ HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wine
     if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
 
     wined3d_mutex_lock();
-    hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, 4,
-            &device->device_parent, &device->wined3d_device);
-    if (FAILED(hr))
+    if (FAILED(hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, 4,
+            &device->device_parent, &device->wined3d_device)))
     {
         WARN("Failed to create wined3d device, hr %#x.\n", hr);
         wined3d_mutex_unlock();
         return hr;
     }
 
+    wined3d_get_device_caps(wined3d, adapter, device_type, &caps);
+    device->max_user_clip_planes = caps.MaxUserClipPlanes;
     if (flags & D3DCREATE_ADAPTERGROUP_DEVICE)
-    {
-        WINED3DCAPS caps;
-
-        wined3d_get_device_caps(wined3d, adapter, device_type, &caps);
         count = caps.NumberOfAdaptersInGroup;
-    }
 
     if (flags & D3DCREATE_MULTITHREADED)
         wined3d_device_set_multithreaded(device->wined3d_device);
diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c
index bcdfd0e..866f435 100644
--- a/dlls/d3d9/tests/device.c
+++ b/dlls/d3d9/tests/device.c
@@ -12026,13 +12026,10 @@ static void test_clip_planes_limits(void)
         {
             memset(plane, 0xff, sizeof(plane));
             hr = IDirect3DDevice9_GetClipPlane(device, j, plane);
-            todo_wine_if(j >= caps.MaxUserClipPlanes)
-            {
             ok(hr == D3D_OK, "Failed to get clip plane %u, hr %#x.\n", j, hr);
             ok(!plane[0] && !plane[1] && !plane[2] && !plane[3],
                     "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
                     j, plane[0], plane[1], plane[2], plane[3]);
-            }
         }
 
         plane[0] = 2.0f;
@@ -12042,7 +12039,6 @@ static void test_clip_planes_limits(void)
         {
             plane[3] = j;
             hr = IDirect3DDevice9_SetClipPlane(device, j, plane);
-            todo_wine_if(j >= caps.MaxUserClipPlanes)
             ok(hr == D3D_OK, "Failed to set clip plane %u, hr %#x.\n", j, hr);
         }
         for (j = 0; j < 2 * D3DMAXUSERCLIPPLANES; ++j)
@@ -12050,9 +12046,7 @@ static void test_clip_planes_limits(void)
             float expected_d = j >= caps.MaxUserClipPlanes - 1 ? 2 * D3DMAXUSERCLIPPLANES - 1 : j;
             memset(plane, 0xff, sizeof(plane));
             hr = IDirect3DDevice9_GetClipPlane(device, j, plane);
-            todo_wine_if(j >= caps.MaxUserClipPlanes)
             ok(hr == D3D_OK, "Failed to get clip plane %u, hr %#x.\n", j, hr);
-            todo_wine_if(j >= caps.MaxUserClipPlanes - 1)
             ok(plane[0] == 2.0f && plane[1] == 8.0f && plane[2] == 5.0f && plane[3] == expected_d,
                     "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
                     j, plane[0], plane[1], plane[2], plane[3]);




More information about the wine-cvs mailing list