D3D: Don't crash when SetRenderTarget() is called with a NULL pSurface

H. Verbeet hverbeet at gmail.com
Sat Aug 5 16:41:29 CDT 2006


Passing a NULL pSurface to SetRenderTarget is valid, so we shouldn't crash.
-------------- next part --------------
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index 18ea822..1d12290 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -579,7 +579,7 @@ static HRESULT WINAPI IDirect3DDevice8Im
 
     IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL == pZSurface ? NULL : (IWineD3DSurface *)pZSurface->wineD3DSurface);
 
-    return IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, (IWineD3DSurface *)pSurface->wineD3DSurface);
+    return IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface ? (IWineD3DSurface *)pSurface->wineD3DSurface : NULL);
 }
 
 static HRESULT  WINAPI  IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index 7aac0e4..ad415a8 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -380,7 +380,7 @@ static HRESULT  WINAPI  IDirect3DDevice9
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
     TRACE("(%p) Relay\n" , This);
-    return IWineD3DDevice_SetRenderTarget(This->WineD3DDevice,RenderTargetIndex,(IWineD3DSurface*)pSurface->wineD3DSurface);
+    return IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? (IWineD3DSurface*)pSurface->wineD3DSurface : NULL);
 }
 
 static HRESULT  WINAPI  IDirect3DDevice9Impl_GetRenderTarget(LPDIRECT3DDEVICE9 iface, DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget) {


More information about the wine-patches mailing list