diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 17664b16b2..a70832d992 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -1226,6 +1226,12 @@ static HRESULT WINAPI d3d9_device_SetRenderTarget(IDirect3DDevice9Ex *iface, DWO return D3DERR_INVALIDCALL; } + if (!idx && !surface_impl) + { + WARN("Trying to set render target 0 to NULL.\n"); + return D3DERR_INVALIDCALL; + } + wined3d_mutex_lock(); hr = wined3d_device_set_render_target(device->wined3d_device, idx, surface_impl ? surface_impl->wined3d_surface : NULL, TRUE); diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c index 15145c0d26..2c02d65b08 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -1827,10 +1827,15 @@ static HRESULT d3d_device_set_render_target(struct d3d_device *device, struct dd wined3d_mutex_unlock(); return D3D_OK; } + if (!target) + { + WARN("Trying to set render target to NULL.\n"); + wined3d_mutex_unlock(); + return DDERR_INVALIDPARAMS; + } device->target = target; - hr = wined3d_device_set_render_target(device->wined3d_device, 0, - target ? target->wined3d_surface : NULL, FALSE); - if(hr != D3D_OK) + if (FAILED(hr = wined3d_device_set_render_target(device->wined3d_device, + 0, target->wined3d_surface, FALSE))) { wined3d_mutex_unlock(); return hr; diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 1b0137fe12..ef0ba9e6a3 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -1350,7 +1350,8 @@ HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device) TRACE("Setting rendertarget 0 to NULL\n"); device->fb.render_targets[0] = NULL; TRACE("Releasing the render target at %p\n", surface); - wined3d_surface_decref(surface); + if (surface) + wined3d_surface_decref(surface); context_release(context); @@ -4482,13 +4483,6 @@ HRESULT CDECL wined3d_device_set_render_target(struct wined3d_device *device, return WINED3DERR_INVALIDCALL; } - /* Render target 0 can't be set to NULL. */ - if (!render_target && !render_target_idx) - { - WARN("Trying to set render target 0 to NULL.\n"); - return WINED3DERR_INVALIDCALL; - } - if (render_target && !(render_target->resource.usage & WINED3DUSAGE_RENDERTARGET)) { FIXME("Surface %p doesn't have render target usage.\n", render_target);