d3d9: Clamp clip plane index to valid range.

Signed-off-by: Józef Kucia <jkucia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Józef Kucia 2017-12-02 10:24:38 +01:00 committed by Alexandre Julliard
parent 462bbf4d20
commit 93d45c04c4
3 changed files with 12 additions and 15 deletions

View File

@ -97,6 +97,8 @@ struct d3d9_device
BOOL in_scene; BOOL in_scene;
BOOL has_vertex_declaration; BOOL has_vertex_declaration;
unsigned int max_user_clip_planes;
UINT implicit_swapchain_count; UINT implicit_swapchain_count;
struct d3d9_swapchain **implicit_swapchains; struct d3d9_swapchain **implicit_swapchains;
}; };

View File

@ -2030,6 +2030,8 @@ static HRESULT WINAPI d3d9_device_SetClipPlane(IDirect3DDevice9Ex *iface, DWORD
TRACE("iface %p, index %u, plane %p.\n", iface, index, plane); TRACE("iface %p, index %u, plane %p.\n", iface, index, plane);
index = min(index, device->max_user_clip_planes - 1);
wined3d_mutex_lock(); wined3d_mutex_lock();
hr = wined3d_device_set_clip_plane(device->wined3d_device, index, (const struct wined3d_vec4 *)plane); hr = wined3d_device_set_clip_plane(device->wined3d_device, index, (const struct wined3d_vec4 *)plane);
wined3d_mutex_unlock(); 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); TRACE("iface %p, index %u, plane %p.\n", iface, index, plane);
index = min(index, device->max_user_clip_planes - 1);
wined3d_mutex_lock(); wined3d_mutex_lock();
hr = wined3d_device_get_clip_plane(device->wined3d_device, index, (struct wined3d_vec4 *)plane); hr = wined3d_device_get_clip_plane(device->wined3d_device, index, (struct wined3d_vec4 *)plane);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
@ -4012,7 +4016,8 @@ HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wine
D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode) D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode)
{ {
struct wined3d_swapchain_desc *swapchain_desc; struct wined3d_swapchain_desc *swapchain_desc;
UINT i, count = 1; unsigned i, count = 1;
WINED3DCAPS caps;
HRESULT hr; HRESULT hr;
if (mode) 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(); if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
wined3d_mutex_lock(); wined3d_mutex_lock();
hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, 4, if (FAILED(hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, 4,
&device->device_parent, &device->wined3d_device); &device->device_parent, &device->wined3d_device)))
if (FAILED(hr))
{ {
WARN("Failed to create wined3d device, hr %#x.\n", hr); WARN("Failed to create wined3d device, hr %#x.\n", hr);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
return hr; return hr;
} }
wined3d_get_device_caps(wined3d, adapter, device_type, &caps);
device->max_user_clip_planes = caps.MaxUserClipPlanes;
if (flags & D3DCREATE_ADAPTERGROUP_DEVICE) if (flags & D3DCREATE_ADAPTERGROUP_DEVICE)
{
WINED3DCAPS caps;
wined3d_get_device_caps(wined3d, adapter, device_type, &caps);
count = caps.NumberOfAdaptersInGroup; count = caps.NumberOfAdaptersInGroup;
}
if (flags & D3DCREATE_MULTITHREADED) if (flags & D3DCREATE_MULTITHREADED)
wined3d_device_set_multithreaded(device->wined3d_device); wined3d_device_set_multithreaded(device->wined3d_device);

View File

@ -12026,13 +12026,10 @@ static void test_clip_planes_limits(void)
{ {
memset(plane, 0xff, sizeof(plane)); memset(plane, 0xff, sizeof(plane));
hr = IDirect3DDevice9_GetClipPlane(device, j, 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(hr == D3D_OK, "Failed to get clip plane %u, hr %#x.\n", j, hr);
ok(!plane[0] && !plane[1] && !plane[2] && !plane[3], ok(!plane[0] && !plane[1] && !plane[2] && !plane[3],
"Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n", "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
j, plane[0], plane[1], plane[2], plane[3]); j, plane[0], plane[1], plane[2], plane[3]);
}
} }
plane[0] = 2.0f; plane[0] = 2.0f;
@ -12042,7 +12039,6 @@ static void test_clip_planes_limits(void)
{ {
plane[3] = j; plane[3] = j;
hr = IDirect3DDevice9_SetClipPlane(device, j, plane); 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); ok(hr == D3D_OK, "Failed to set clip plane %u, hr %#x.\n", j, hr);
} }
for (j = 0; j < 2 * D3DMAXUSERCLIPPLANES; ++j) 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; float expected_d = j >= caps.MaxUserClipPlanes - 1 ? 2 * D3DMAXUSERCLIPPLANES - 1 : j;
memset(plane, 0xff, sizeof(plane)); memset(plane, 0xff, sizeof(plane));
hr = IDirect3DDevice9_GetClipPlane(device, j, 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(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, 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", "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
j, plane[0], plane[1], plane[2], plane[3]); j, plane[0], plane[1], plane[2], plane[3]);