Commit 93d45c04 authored by Józef Kucia's avatar Józef Kucia Committed by Alexandre Julliard

d3d9: Clamp clip plane index to valid range.

parent 462bbf4d
......@@ -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;
};
......
......@@ -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);
......
......@@ -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]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment