[d3d9] cleanup and NULL check [bug-5839]

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[d3d9] cleanup and NULL check [bug-5839]

Oliver Stieber
Hi,
   This patch checks relevant input parameters to see if they are NULL and tidies
up some traces and error handling.

It also partly fixes bug 5839

Oliver.


       
       
               
___________________________________________________________
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com
diff -X ignore -Nruw clean/wine/dlls/d3d9/cubetexture.c smallpatches/wine/dlls/d3d9/cubetexture.c
--- clean/wine/dlls/d3d9/cubetexture.c 2005-08-23 17:05:25.896922720 +0100
+++ smallpatches/wine/dlls/d3d9/cubetexture.c 2005-10-12 14:39:50.044001500 +0100
@@ -159,6 +159,11 @@
 
     TRACE("(%p) Relay\n", This);
 
+    if (NULL == pDesc) {
+        WARN("(%p) : Caller passed null as pDesc returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
     wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
     wined3ddesc.Type                = &pDesc->Type;
@@ -180,10 +185,17 @@
 
     TRACE("(%p) Relay\n", This);
 
+    if (NULL == ppCubeMapSurface) {
+        WARN("(%p) : Caller passed null as ppCubeMapSurface returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, FaceType, Level, &mySurface);
-    if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
+    if (hrc == D3D_OK) {
        IWineD3DCubeTexture_GetParent(mySurface, (IUnknown **)ppCubeMapSurface);
        IWineD3DCubeTexture_Release(mySurface);
+    } else {
+        WARN("(%p) : Warn call to IWineD3DCubeTexture_GetCubeMapSurface failed\n", This);
     }
     return hrc;
 }
@@ -255,7 +267,7 @@
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
 
     if (NULL == object) {
-        FIXME("(%p) allocation of CubeTexture failed\n", This);
+        FIXME("(%p) allocation of CubeTexture failed, returning D3DERR_OUTOFVIDEOMEMORY\n", This);
         *ppCubeTexture = NULL;
         return D3DERR_OUTOFVIDEOMEMORY;
     }
diff -X ignore -Nruw clean/wine/dlls/d3d9/device.c smallpatches/wine/dlls/d3d9/device.c
--- clean/wine/dlls/d3d9/device.c 2005-08-23 17:05:25.991908280 +0100
+++ smallpatches/wine/dlls/d3d9/device.c 2005-10-12 16:33:16.369370250 +0100
@@ -101,7 +101,7 @@
         IWineD3DResource_GetParent((IWineD3DResource *)pWineD3D,(IUnknown **)ppD3D9);
         IWineD3DResource_Release((IWineD3DResource *)pWineD3D);
     } else {
-        FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
+        WARN("Call to IWineD3DDevice_GetDirect3D failed\n");
         *ppD3D9 = NULL;
     }
     TRACE("(%p) returning %p\b",This , *ppD3D9);
@@ -115,10 +115,12 @@
 
     TRACE("(%p) : Relay pCaps %p \n", This, pCaps);
     if(NULL == pCaps){
+        WARN("(%p) : Caller passed NULL as pCaps returning D3DERR_INVALIDCALL\n", This);
         return D3DERR_INVALIDCALL;
     }
     pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
     if(pWineCaps == NULL){
+        WARN("(%p) : Failed to allocate memory for pWineCaps, returning D3DERR_INVALIDCALL\n", This);
         return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
     }
 
@@ -197,10 +199,17 @@
 
     TRACE("(%p) Relay\n", This);
 
+    if (NULL == ppBackBuffer) {
+        WARN("(%p) : Caller passed NULL as ppBackBuffer returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain, BackBuffer, Type, (IWineD3DSurface **)&retSurface);
-    if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
+    if (rc == D3D_OK) {
         IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
         IWineD3DSurface_Release(retSurface);
+    } else {
+        WARN("(%p) : call to IWineD3DDevice_GetBackBuffer failed\n", This);
     }
     return rc;
 }
@@ -219,7 +228,6 @@
 }
 
 void WINAPI IDirect3DDevice9Impl_SetGammaRamp(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
-    
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     TRACE("(%p) Relay\n", This);
     
@@ -239,6 +247,13 @@
     IDirect3DSurface9Impl *object;
     IDirect3DDevice9Impl  *This = (IDirect3DDevice9Impl *)iface;
     TRACE("(%p) Relay\n", This);
+
+    if (NULL == ppSurface ) {
+        WARN("(%p) : Caller passed null as ppSurface, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
+    /* TODO: Move MultisampleQuality checks to wined3d */
     if(MultisampleQuality < 0) {
         FIXME("MultisampleQuality out of range %ld, substituting 0 \n", MultisampleQuality);
     /*FIXME: Find out what windows does with a MultisampleQuality < 0 */
@@ -251,7 +266,6 @@
     MultisampleQuality
  [in] Quality level. The valid range is between zero and one less than the level returned by pQualityLevels used by IDirect3D9::CheckDeviceMultiSampleType. Passing a larger value returns the error D3DERR_INVALIDCALL. The MultisampleQuality values of paired render targets, depth stencil surfaces, and the MultiSample type must all match.
  */
-
         MultisampleQuality=0;
     }
     /*FIXME: Check MAX bounds of MultisampleQuality*/
@@ -259,7 +273,7 @@
     /* Allocate the storage for the device */
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
     if (NULL == object) {
-        FIXME("Allocation of memory failed\n");
+        WARN("Allocation of memory failed\n");
         *ppSurface = NULL;
         return D3DERR_OUTOFVIDEOMEMORY;
     }
@@ -269,11 +283,13 @@
     
     TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
           
-    hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, Format, Lockable, Discard, Level,  &object->wineD3DSurface, Type, Usage, Pool,MultiSample,MultisampleQuality,pSharedHandle,(IUnknown *)object);
+    hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, Format, Lockable, Discard,
+                                        Level, &object->wineD3DSurface, Type, Usage, Pool, MultiSample,
+                                        MultisampleQuality, pSharedHandle, (IUnknown *)object);
     
     if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
        /* free up object */
-        FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
+        WARN("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
         HeapFree(GetProcessHeap(), 0, object);
         *ppSurface = NULL;
     } else {
@@ -289,10 +305,8 @@
                                                          DWORD MultisampleQuality, BOOL Lockable,
                                                          IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
    TRACE("Relay\n");
-   /* Is this correct? */
-   return IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,Lockable,FALSE/*Discard*/, 0/*Level*/, ppSurface,D3DRTYPE_SURFACE,D3DUSAGE_RENDERTARGET,D3DPOOL_DEFAULT,MultiSample,MultisampleQuality,pSharedHandle);
-    
 
+   return IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE/*Discard*/, 0/*Level*/, ppSurface, D3DRTYPE_SURFACE, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality, pSharedHandle);
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE9 iface, UINT Width, UINT Height,
@@ -309,13 +323,15 @@
 HRESULT  WINAPI  IDirect3DDevice9Impl_UpdateSurface(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;    
     TRACE("(%p) Relay\n" , This);
-    return IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
+    return IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, NULL == pDestinationSurface ? NULL : ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_UpdateTexture(LPDIRECT3DDEVICE9 iface, IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IDirect3DBaseTexture9Impl *sourceTexture = (IDirect3DBaseTexture9Impl *)pSourceTexture;
+    IDirect3DBaseTexture9Impl *destTexture   = (IDirect3DBaseTexture9Impl *)pDestinationTexture;
     TRACE("(%p) Relay\n" , This);
-    return IWineD3DDevice_UpdateTexture(This->WineD3DDevice,  ((IDirect3DBaseTexture9Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture9Impl *)pDestinationTexture)->wineD3DBaseTexture);
+    return IWineD3DDevice_UpdateTexture(This->WineD3DDevice,  sourceTexture == NULL ? sourceTexture : sourceTexture->wineD3DBaseTexture, NULL == destTexture ? NULL : destTexture->wineD3DBaseTexture);
 }
 
 /* This isn't in MSDN!
@@ -331,33 +347,35 @@
     IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
     IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
     TRACE("(%p) Relay\n" , This);
-    return IWineD3DDevice_GetRenderTargetData(This->WineD3DDevice, renderTarget->wineD3DSurface, destSurface->wineD3DSurface);
+    return IWineD3DDevice_GetRenderTargetData(This->WineD3DDevice, NULL == renderTarget ? NULL : renderTarget->wineD3DSurface, NULL == destSurface ? NULL : destSurface->wineD3DSurface);
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_GetFrontBufferData(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, IDirect3DSurface9* pDestSurface) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
     TRACE("(%p) Relay\n" , This);
-    return IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);    
+    return IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, NULL == destSurface ? NULL : destSurface->wineD3DSurface);
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_StretchRect(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;    
+    IDirect3DSurface9Impl *sourceTarget = (IDirect3DSurface9Impl *)pSourceSurface;
+    IDirect3DSurface9Impl *destSurface  = (IDirect3DSurface9Impl *)pDestSurface;
     TRACE("(%p) Relay\n" , This);
-    return IWineD3DDevice_StretchRect(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestSurface)->wineD3DSurface, pDestRect, Filter);            
+    return IWineD3DDevice_StretchRect(This->WineD3DDevice, NULL == sourceTarget ? NULL : sourceTarget->wineD3DSurface, pSourceRect, NULL == destSurface ? NULL : destSurface->wineD3DSurface, pDestRect, Filter);
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_ColorFill(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
     TRACE("(%p) Relay\n" , This);
-    return IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, (CONST D3DRECT*)pRect, color);    
+    return IWineD3DDevice_ColorFill(This->WineD3DDevice, NULL == surface ? NULL : surface->wineD3DSurface, (CONST D3DRECT *)pRect, color);
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
     TRACE("Relay\n");
     if(Pool == D3DPOOL_MANAGED ){
-        FIXME("Attempting to create a managed offscreen plain surface\n");
+        WARN("Attempting to create a managed offscreen plain surface, returning D3DERR_INVALIDCALL\n");
         return D3DERR_INVALIDCALL;
     }    
         /*MSDN: D3DPOOL_SCRATCH will return a surface that has identical characteristics to a surface created by the Microsoft DirectX 8.x method CreateImageSurface.
@@ -374,9 +392,9 @@
 /* TODO: move to wineD3D */
 HRESULT  WINAPI  IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9 iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
+    IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
     TRACE("(%p) Relay\n" , This);
-    return IWineD3DDevice_SetRenderTarget(This->WineD3DDevice,RenderTargetIndex,(IWineD3DSurface*)pSurface->wineD3DSurface);
+    return IWineD3DDevice_SetRenderTarget(This->WineD3DDevice,RenderTargetIndex, renderTarget == NULL ? NULL : renderTarget->wineD3DSurface);
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_GetRenderTarget(LPDIRECT3DDEVICE9 iface, DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget) {
@@ -387,15 +405,17 @@
     TRACE("(%p) Relay\n" , This);
 
     if (ppRenderTarget == NULL) {
+        WARN("(%p) : Caller sent NULL as ppRenderTarget, returning D3DERR_INVALIDCALL\n", This);
         return D3DERR_INVALIDCALL;
     }
+
     hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
 
-    if (hr == D3D_OK && pRenderTarget != NULL) {
-        IWineD3DResource_GetParent((IWineD3DResource *)pRenderTarget,(IUnknown**)ppRenderTarget);
-        IWineD3DResource_Release((IWineD3DResource *)pRenderTarget);
+    if (hr == D3D_OK) {
+        IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
+        IWineD3DSurface_Release(pRenderTarget);
     } else {
-        FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
+        WARN("Call to IWineD3DDevice_GetRenderTarget failed\n");
         *ppRenderTarget = NULL;
     }
     return hr;
@@ -403,12 +423,11 @@
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pZStencilSurface) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    IDirect3DSurface9Impl *pSurface;
+    IDirect3DSurface9Impl *zSteincilSurface = (IDirect3DSurface9Impl *)pZStencilSurface;
 
     TRACE("(%p) Relay\n" , This);
 
-    pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
-    return IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice,NULL==pSurface?NULL:(IWineD3DSurface*)pSurface->wineD3DSurface);
+    return IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice , NULL == zSteincilSurface ? NULL : zSteincilSurface->wineD3DSurface);
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9 **ppZStencilSurface) {
@@ -418,15 +437,16 @@
 
     TRACE("(%p) Relay\n" , This);
     if(ppZStencilSurface == NULL){
+        WARN("(%p) : Caller sent NULL as ppZStencilSurface, returning D3DERR_INVALIDCALL\n", This);
         return D3DERR_INVALIDCALL;
     }
 
     hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
     if(hr == D3D_OK && pZStencilSurface != NULL){
-        IWineD3DResource_GetParent((IWineD3DResource *)pZStencilSurface,(IUnknown**)ppZStencilSurface);
-        IWineD3DResource_Release((IWineD3DResource *)pZStencilSurface);
+        IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
+        IWineD3DSurface_Release(pZStencilSurface);
     }else{
-        FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
+        WARN("Call to IWineD3DDevice_GetRenderTarget failed\n");
         *ppZStencilSurface = NULL;
     }
     return D3D_OK;
@@ -441,8 +461,8 @@
 HRESULT  WINAPI  IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9 iface) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     TRACE("(%p) Relay\n" , This);
-    return IWineD3DDevice_EndScene(This->WineD3DDevice);
     
+    return IWineD3DDevice_EndScene(This->WineD3DDevice);
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
@@ -560,7 +580,8 @@
 
     TRACE("(%p) Relay\n" , This);
 
-    if(ppTexture == NULL){
+    if (NULL == ppTexture) {
+        WARN("(%p) : Caller sent NULL as ppTexture, returning D3DERR_INVALIDCALL\n", This);
         return D3DERR_INVALIDCALL;
     }
 
@@ -569,7 +590,7 @@
         IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
         IWineD3DBaseTexture_Release(retTexture);
     }else{
-        FIXME("Call to get texture  (%ld) failed (%p) \n", Stage, retTexture);
+        WARN("Call to get texture (%ld) failed (%p) \n", Stage, retTexture);
         *ppTexture = NULL;
     }
     return rc;
@@ -577,9 +598,10 @@
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_SetTexture(LPDIRECT3DDEVICE9 iface, DWORD Stage, IDirect3DBaseTexture9* pTexture) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IDirect3DBaseTexture9Impl *texture = (IDirect3DBaseTexture9Impl *)pTexture;
     TRACE("(%p) Relay %ld %p\n" , This, Stage, pTexture);
     return IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
-                                     pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture);
+                                     NULL == texture ? NULL : texture->wineD3DBaseTexture);
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) {
@@ -733,16 +755,17 @@
 
     TRACE("(%p) Relay\n" , This);
 
-    if(pStream == NULL){
+    if(NULL == pStream){
+        WARN("(%p) : Caller sent NULL as pStream, returning D3DERR_INVALIDCALL\n", This);
         return D3DERR_INVALIDCALL;
     }
 
     rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, (IWineD3DVertexBuffer **)&retStream, OffsetInBytes, pStride);
-    if (rc == D3D_OK  && NULL != retStream) {
+    if (rc == D3D_OK) {
         IWineD3DVertexBuffer_GetParent(retStream, (IUnknown **)pStream);
         IWineD3DVertexBuffer_Release(retStream);
     }else{
-        FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
+        WARN("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
         *pStream = NULL;
     }
     return rc;
@@ -759,15 +782,14 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     TRACE("(%p) Relay\n" , This);
     return IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
-    return D3D_OK;
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9 iface, IDirect3DIndexBuffer9* pIndexData) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IDirect3DIndexBuffer9Impl *indexData = (IDirect3DIndexBuffer9Impl *)pIndexData;
     TRACE("(%p) Relay\n", This);
     return IWineD3DDevice_SetIndices(This->WineD3DDevice,
-                                     pIndexData==NULL ? NULL:((IDirect3DIndexBuffer9Impl *)pIndexData)->wineD3DIndexBuffer,
-                                     0);
+                                     NULL == indexData ? NULL : indexData->wineD3DIndexBuffer, 0);
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_GetIndices(LPDIRECT3DDEVICE9 iface, IDirect3DIndexBuffer9 **ppIndexData) {
@@ -779,15 +801,16 @@
     TRACE("(%p) Relay\n", This);
 
     if(ppIndexData == NULL){
+        WARN("(%p) : Caller sent NULL as ppIndexData, returning D3DERR_INVALIDCALL\n", This);
         return D3DERR_INVALIDCALL;
     }
 
     rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData, &tmp);
-    if (rc == D3D_OK && NULL != retIndexData) {
+    if (rc == D3D_OK) {
         IWineD3DVertexBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
         IWineD3DVertexBuffer_Release(retIndexData);
     }else{
-        if(rc != D3D_OK)  FIXME("Call to GetIndices failed\n");
+        WARN("Call to GetIndices failed\n");
         *ppIndexData = NULL;
     }
     return rc;
@@ -941,7 +964,6 @@
 HRESULT WINAPI D3D9CB_CreateSurface(IUnknown *device, UINT Width, UINT Height,
                                          WINED3DFORMAT Format, DWORD Usage, D3DPOOL Pool, UINT Level,
                                          IWineD3DSurface** ppSurface, HANDLE* pSharedHandle) {
-    
     HRESULT res = D3D_OK;
     IDirect3DSurface9Impl *d3dSurface = NULL;
     BOOL Lockable = TRUE;
@@ -955,7 +977,7 @@
     if (res == D3D_OK) {
         *ppSurface = d3dSurface->wineD3DSurface;
     }else{
-        FIXME("(%p) IDirect3DDevice9_CreateSurface failed\n", device);
+        WARN("(%p) IDirect3DDevice9_CreateSurface failed\n", device);
     }
     return res;
 }
diff -X ignore -Nruw clean/wine/dlls/d3d9/directx.c smallpatches/wine/dlls/d3d9/directx.c
--- clean/wine/dlls/d3d9/directx.c 2005-08-23 17:05:26.015904632 +0100
+++ smallpatches/wine/dlls/d3d9/directx.c 2005-10-12 16:34:17.973220250 +0100
@@ -78,6 +78,10 @@
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
     WINED3DADAPTER_IDENTIFIER adapter_id;
 
+    if (NULL == pIdentifier) {
+        WARN("(%p) : caller passed parameter pIdentifier as NULL, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
     /* dx8 and dx9 have different structures to be filled in, with incompatible
        layouts so pass in pointers to the places to be filled via an internal
        structure                                                                */
@@ -156,10 +160,12 @@
     TRACE("(%p) Relay %d %u %p \n", This, Adapter, DeviceType, pCaps);
 
     if(NULL == pCaps){
+        WARN("(%p) : Caller passed parameter pCaps as NULL, returning D3DERR_INVALIDCALL\n", This);
         return D3DERR_INVALIDCALL;
     }
     pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
     if(pWineCaps == NULL){
+        WARN("(%p) : Out of memory\n", This);
         return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
     }
     D3D9CAPSTOWINECAPS(pCaps, pWineCaps)
@@ -258,6 +264,8 @@
                                          (IDirect3DSurface9 **)&d3dSurface, pSharedHandle);
     if (res == D3D_OK) {
         *ppSurface = d3dSurface->wineD3DSurface;
+    } else {
+        WARN("(%p) : call to IDirect3DDevice9_CreateDepthStencilSurface failed\n", device);
     }
     return res;
 }
@@ -276,13 +284,14 @@
     /* Check the validity range of the adapter parameter */
     if (Adapter >= IDirect3D9Impl_GetAdapterCount(iface)) {
         *ppReturnedDeviceInterface = NULL;
+        WARN("(%p) : Caller passed parameter ppReturnedDeviceInterface as NULL, returning D3DERR_INVALIDCALL\n", This);
         return D3DERR_INVALIDCALL;
     }
 
     /* Allocate the storage for the device object */
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DDevice9Impl));
     if (NULL == object) {
-        FIXME("Allocation of memory failed\n");
+        WARN("Allocation of memory failed\n");
         *ppReturnedDeviceInterface = NULL;
         return D3DERR_OUTOFVIDEOMEMORY;
     }
@@ -313,6 +322,7 @@
 
         TRACE("(%p) : Created Device %p\n", This, object);
     } else {
+        WARN("(%p) : call to IWineD3D_CreateDevice failed\n", This);
         HeapFree(GetProcessHeap(), 0, object);
         *ppReturnedDeviceInterface = NULL;
     }
diff -X ignore -Nruw clean/wine/dlls/d3d9/indexbuffer.c smallpatches/wine/dlls/d3d9/indexbuffer.c
--- clean/wine/dlls/d3d9/indexbuffer.c 2005-08-23 17:05:26.029902504 +0100
+++ smallpatches/wine/dlls/d3d9/indexbuffer.c 2005-10-12 15:14:02.400265750 +0100
@@ -163,6 +163,11 @@
     HRESULT hrc = D3D_OK;
     
     TRACE("(%p) Relay\n", This);
+
+    if (NULL == ppIndexBuffer) {
+        WARN("(%p) : caller passed NULL for parameter ppIndexBuffer, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
     /* Allocate the storage for the device */
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if (NULL == object) {
diff -X ignore -Nruw clean/wine/dlls/d3d9/pixelshader.c smallpatches/wine/dlls/d3d9/pixelshader.c
--- clean/wine/dlls/d3d9/pixelshader.c 2005-08-23 17:05:26.046899920 +0100
+++ smallpatches/wine/dlls/d3d9/pixelshader.c 2005-10-12 15:19:04.067118750 +0100
@@ -65,14 +65,25 @@
 HRESULT WINAPI IDirect3DPixelShader9Impl_GetDevice(LPDIRECT3DPIXELSHADER9 iface, IDirect3DDevice9** ppDevice) {
     IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
     IWineD3DDevice *myDevice = NULL;
+    HRESULT hr;
 
     TRACE("(%p) : Relay\n", This);
 
-    IWineD3DPixelShader_GetDevice(This->wineD3DPixelShader, &myDevice);
+    if (NULL == ppDevice) {
+        WARN("(%p) : Caller passed NULL as parameter ppDevice, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
+    hr = IWineD3DPixelShader_GetDevice(This->wineD3DPixelShader, &myDevice);
+    if (D3D_OK == hr) {
     IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
     IWineD3DDevice_Release(myDevice);
+    } else {
+        WARN("(%p) : Call to IWineD3DPixelShader_GetDevice failed\n", This);
+    }
+
     TRACE("(%p) returing (%p)", This, *ppDevice);
-    return D3D_OK;
+    return hr;
 }
 
 HRESULT WINAPI IDirect3DPixelShader9Impl_GetFunction(LPDIRECT3DPIXELSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
@@ -104,14 +115,15 @@
     *ppShader = NULL;
     return D3D_OK;
     if (ppShader == NULL) {
-        TRACE("(%p) Invalid call\n", This);
+        WARN("(%p) : Caller passed NULL as parameter ppShader, returning D3DERR_INVALIDCALL\n", This);
         return D3DERR_INVALIDCALL;
     }
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
 
     if (NULL == object) {
+        WARN("(%p) : Out of memory\n", This);
         return E_OUTOFMEMORY;
-    } else {
+    }
 
         object->ref    = 1;
         object->lpVtbl = &Direct3DPixelShader9_Vtbl;
@@ -124,7 +136,6 @@
             *ppShader = (IDirect3DPixelShader9*) object;
         }
 
-    }
 
     TRACE("(%p) : returning %p\n", This, *ppShader);
     return hrc;
@@ -145,7 +156,7 @@
     HRESULT hrc = D3D_OK;
     TRACE("(%p) Relay\n", This);
     if (ppShader == NULL) {
-        TRACE("(%p) Invalid call\n", This);
+        WARN("(%p) : Caller passed NULL as parameter ppShader, returning D3DERR_INVALIDCALL\n", This);
         return D3DERR_INVALIDCALL;
     }
 
diff -X ignore -Nruw clean/wine/dlls/d3d9/query.c smallpatches/wine/dlls/d3d9/query.c
--- clean/wine/dlls/d3d9/query.c 2005-05-27 21:17:36.000000000 +0100
+++ smallpatches/wine/dlls/d3d9/query.c 2005-10-12 15:23:02.834040750 +0100
@@ -68,9 +68,14 @@
     HRESULT hr;
 
     TRACE("(%p) Relay\n", This);
+    if (NULL == ppDevice) {
+        WARN("(%p) : Caller passed NULL as parameter ppDevice, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
 
     hr = IWineD3DQuery_GetDevice(This->wineD3DQuery, &pDevice);
     if(hr != D3D_OK){
+        WARN("(%p) : Call to IWineD3DQuery_GetDevice failed\n", This);
         *ppDevice = NULL;
     }else{
         hr = IWineD3DDevice_GetParent(pDevice, (IUnknown **)ppDevice);
@@ -106,9 +111,11 @@
 
 const IDirect3DQuery9Vtbl Direct3DQuery9_Vtbl =
 {
+    /* IUnknown */
     IDirect3DQuery9Impl_QueryInterface,
     IDirect3DQuery9Impl_AddRef,
     IDirect3DQuery9Impl_Release,
+    /* IDirect3DQuery */
     IDirect3DQuery9Impl_GetDevice,
     IDirect3DQuery9Impl_GetType,
     IDirect3DQuery9Impl_GetDataSize,
@@ -125,12 +132,13 @@
 
   TRACE("(%p) Relay\n", This);
   if (NULL == ppQuery) {
+        WARN("(%p) : Caller passed NULL as parameter ppQuery, returning D3DERR_INVALIDCALL\n", This);
     return D3DERR_INVALIDCALL;
   }
   /* Allocate the storage for the device */
   object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DQuery9Impl));
   if (NULL == object) {
-    FIXME("Allocation of memory failed\n");
+        WARN("Allocation of memory failed\n");
     *ppQuery = NULL;
     return D3DERR_OUTOFVIDEOMEMORY;
   }
@@ -141,7 +149,7 @@
   
   if (FAILED(hr)) {
     /* free up object */
-    FIXME("(%p) call to IWineD3DDevice_CreateQuery failed\n", This);
+        WARN("(%p) call to IWineD3DDevice_CreateQuery failed\n", This);
     HeapFree(GetProcessHeap(), 0, object);
     *ppQuery = NULL;
   } else {
diff -X ignore -Nruw clean/wine/dlls/d3d9/resource.c smallpatches/wine/dlls/d3d9/resource.c
--- clean/wine/dlls/d3d9/resource.c 2005-05-27 21:17:36.000000000 +0100
+++ smallpatches/wine/dlls/d3d9/resource.c 2005-10-12 15:25:04.857666750 +0100
@@ -65,13 +65,20 @@
 HRESULT WINAPI IDirect3DResource9Impl_GetDevice(LPDIRECT3DRESOURCE9 iface, IDirect3DDevice9** ppDevice) {
     IDirect3DResource9Impl *This = (IDirect3DResource9Impl *)iface;
     IWineD3DDevice *myDevice = NULL;
+    HRESULT hr;
 
     TRACE("(%p) Relay\n", This);
+    if (NULL == ppDevice) {
+        WARN("(%p) : Caller passed NULL as parameter ppDevice, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
 
-    IWineD3DResource_GetDevice(This->wineD3DResource, &myDevice);
+    hr = IWineD3DResource_GetDevice(This->wineD3DResource, &myDevice);
+    if (D3D_OK == hr) {
     IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
     IWineD3DDevice_Release(myDevice);
-    return D3D_OK;
+    }
+    return hr;
 }
 
 HRESULT WINAPI IDirect3DResource9Impl_SetPrivateData(LPDIRECT3DRESOURCE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
@@ -120,9 +127,11 @@
 
 const IDirect3DResource9Vtbl Direct3DResource9_Vtbl =
 {
+    /* IUnknown */
     IDirect3DResource9Impl_QueryInterface,
     IDirect3DResource9Impl_AddRef,
     IDirect3DResource9Impl_Release,
+    /* IDirect3DResource9 */
     IDirect3DResource9Impl_GetDevice,
     IDirect3DResource9Impl_SetPrivateData,
     IDirect3DResource9Impl_GetPrivateData,
diff -X ignore -Nruw clean/wine/dlls/d3d9/stateblock.c smallpatches/wine/dlls/d3d9/stateblock.c
--- clean/wine/dlls/d3d9/stateblock.c 2005-08-23 17:05:26.071896120 +0100
+++ smallpatches/wine/dlls/d3d9/stateblock.c 2005-10-12 15:28:50.723782500 +0100
@@ -103,9 +103,14 @@
   
    TRACE("(%p) Relay\n", This);
   
+    if (NULL == ppStateBlock) {
+        WARN("(%p) : Caller passed NULL as parameter ppStateBlock, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
    object  = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock9Impl));
    if (NULL == object) {
-      FIXME("(%p)  Failed to allocate %d bytes\n", This, sizeof(IDirect3DStateBlock9Impl));
+        WARN("(%p)  Failed to allocate %d bytes\n", This, sizeof(IDirect3DStateBlock9Impl));
       *ppStateBlock = NULL;
       return E_OUTOFMEMORY;
    }
@@ -138,12 +143,17 @@
 
     TRACE("(%p) Relay\n", This);
     
+    if (NULL == ppSB) {
+        WARN("(%p) : Caller passed NULL as parameter ppSB, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     /* Tell wineD3D to endstatablock before anything else (in case we run out
      * of memory later and cause locking problems)
      */
     hr=IWineD3DDevice_EndStateBlock(This->WineD3DDevice,&wineD3DStateBlock);
     if(hr!= D3D_OK){
-       FIXME("IWineD3DDevice_EndStateBlock returned an error\n");
+       WARN("IWineD3DDevice_EndStateBlock returned an error\n");
        return hr;
     }    
     /* allocate a new IDirectD3DStateBlock */
diff -X ignore -Nruw clean/wine/dlls/d3d9/surface.c smallpatches/wine/dlls/d3d9/surface.c
--- clean/wine/dlls/d3d9/surface.c 2005-08-23 17:05:26.082894448 +0100
+++ smallpatches/wine/dlls/d3d9/surface.c 2005-10-12 15:30:46.363009500 +0100
@@ -119,6 +119,11 @@
 
     TRACE("(%p) Relay\n", This);
 
+    if (NULL == ppContainer) {
+        WARN("(%p) : User passed NULL as parameter ppContainer, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     /* The container returned from IWineD3DSurface_GetContainer is either an IWineD3DDevice,
        one of the subclasses of IWineD3DBaseTexture or an IWineD3DSwapChain  */
     /* Get the IUnknown container. */
@@ -151,7 +156,6 @@
             /* Tidy up.. */
             IUnknown_Release(IUnknownParent);
         }
-        
     }
 
     TRACE("(%p) : returning %p\n", This, *ppContainer);    
diff -X ignore -Nruw clean/wine/dlls/d3d9/swapchain.c smallpatches/wine/dlls/d3d9/swapchain.c
--- clean/wine/dlls/d3d9/swapchain.c 2005-08-23 17:05:26.086893840 +0100
+++ smallpatches/wine/dlls/d3d9/swapchain.c 2005-10-12 17:14:33.600187500 +0100
@@ -72,8 +72,9 @@
 
 HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface) {
     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
+    IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
     TRACE("(%p) Relay\n", This);
-    return IWineD3DSwapChain_GetFrontBufferData(This->wineD3DSwapChain,  ((IDirect3DSurface9Impl *)pDestSurface)->wineD3DSurface);
+    return IWineD3DSwapChain_GetFrontBufferData(This->wineD3DSwapChain, NULL == destSurface ? NULL : destSurface->wineD3DSurface);
 }
 
 HRESULT WINAPI IDirect3DSwapChain9Impl_GetBackBuffer(LPDIRECT3DSWAPCHAIN9 iface, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) {
@@ -82,11 +83,16 @@
     IWineD3DSurface *mySurface = NULL;
 
     TRACE("(%p) Relay\n", This);
-
+    if (NULL == ppBackBuffer) {
+        WARN("(%p) : Caller passed NULL as parameter ppBackBuffer, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
     hrc = IWineD3DSwapChain_GetBackBuffer(This->wineD3DSwapChain, iBackBuffer, Type, &mySurface);
-    if (hrc == D3D_OK && NULL != mySurface) {
+    if (D3D_OK == hrc) {
        IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppBackBuffer);
        IWineD3DSurface_Release(mySurface);
+    } else {
+        WARN("(%p) : Call to IWineD3DSwapChain_GetBackBuffer failed\n", This);
     }
     return hrc;
 }
@@ -110,10 +116,17 @@
 
     TRACE("(%p) Relay\n", This);
 
+    if (NULL == ppDevice) {
+        WARN("(%p) : Caller passed NULL as parameter ppDevice, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     hrc = IWineD3DSwapChain_GetDevice(This->wineD3DSwapChain, &device);
-    if (hrc == D3D_OK && NULL != device) {
+    if (D3D_OK == hrc) {
        IWineD3DDevice_GetParent(device, (IUnknown **)ppDevice);
        IWineD3DDevice_Release(device);
+    } else {
+        WARN("(%p) : Call to IWineD3DSwapChain_GetDevice failed\n", This);
     }
     return hrc;
 }
@@ -127,9 +140,11 @@
 
 const IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl =
 {
+    /* IUnknown */
     IDirect3DSwapChain9Impl_QueryInterface,
     IDirect3DSwapChain9Impl_AddRef,
     IDirect3DSwapChain9Impl_Release,
+    /* IDirect3DSwapchain9 */
     IDirect3DSwapChain9Impl_Present,
     IDirect3DSwapChain9Impl_GetFrontBufferData,
     IDirect3DSwapChain9Impl_GetBackBuffer,
@@ -141,7 +156,7 @@
 
 
 /* IDirect3DDevice9 IDirect3DSwapChain9 Methods follow: */
-HRESULT  WINAPI  IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain) {
+HRESULT  WINAPI  IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE9 iface, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DSwapChain9 **ppSwapChain) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     IDirect3DSwapChain9Impl* object;
     HRESULT hrc = D3D_OK;
@@ -149,10 +164,15 @@
 
     TRACE("(%p) Relay\n", This);
 
+    if (NULL == ppSwapChain) {
+        WARN("(%p) : Caller passed NULL as parameter ppSwapChain, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     object = HeapAlloc(GetProcessHeap(),  HEAP_ZERO_MEMORY, sizeof(*object));
     if (NULL == object) {
         FIXME("Allocation of memory failed\n");
-        *pSwapChain = NULL;
+        *ppSwapChain = NULL;
         return D3DERR_OUTOFVIDEOMEMORY;
     }
     object->ref = 1;
@@ -177,27 +197,34 @@
 
     hrc = IWineD3DDevice_CreateAdditionalSwapChain(This->WineD3DDevice, &localParameters, &object->wineD3DSwapChain, (IUnknown*)object, D3D9CB_CreateRenderTarget, D3D9CB_CreateDepthStencilSurface);
     if (hrc != D3D_OK) {
-        FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This);
+        WARN("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This);
         HeapFree(GetProcessHeap(), 0 , object);
-        *pSwapChain = NULL;
+        *ppSwapChain = NULL;
     }else{
-        *pSwapChain = (IDirect3DSwapChain9 *)object;
+        *ppSwapChain = (IDirect3DSwapChain9 *)object;
     }
-    TRACE("(%p) returning %p\n", This, *pSwapChain);
+    TRACE("(%p) returning %p\n", This, *ppSwapChain);
     return hrc;
 }
 
-HRESULT  WINAPI  IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) {
+HRESULT  WINAPI  IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, IDirect3DSwapChain9 **ppSwapChain) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hrc = D3D_OK;
     IWineD3DSwapChain *swapchain = NULL;
 
     TRACE("(%p) Relay\n", This);
 
+    if (NULL == ppSwapChain) {
+        WARN("(%p) : Caller passed NULL as parameter ppSwapChain, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     hrc = IWineD3DDevice_GetSwapChain(This->WineD3DDevice, iSwapChain, &swapchain);
-    if (hrc == D3D_OK && NULL != swapchain) {
-       IWineD3DSwapChain_GetParent(swapchain, (IUnknown **)pSwapChain);
+    if (D3D_OK == hrc) {
+       IWineD3DSwapChain_GetParent(swapchain, (IUnknown **)ppSwapChain);
        IWineD3DSwapChain_Release(swapchain);
+    } else {
+        WARN("(%p) : Call to IWineD3DDevice_GetSwapChain failed\n", This);
     }
     return hrc;
 }
diff -X ignore -Nruw clean/wine/dlls/d3d9/texture.c smallpatches/wine/dlls/d3d9/texture.c
--- clean/wine/dlls/d3d9/texture.c 2005-08-23 17:05:26.095892472 +0100
+++ smallpatches/wine/dlls/d3d9/texture.c 2005-10-12 15:41:00.273376500 +0100
@@ -158,6 +158,11 @@
     UINT                   tmpInt = -1;
     TRACE("(%p) Relay\n", This);
 
+    if (NULL == pDesc) {
+        WARN("(%p) : Caller passed NULL as parameter pDesc, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
     wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
     wined3ddesc.Type                = &pDesc->Type;
@@ -178,10 +183,18 @@
     IWineD3DSurface *mySurface = NULL;
 
     TRACE("(%p) Relay\n", This);
+
+    if (NULL == ppSurfaceLevel) {
+        WARN("(%p) : Caller passed NULL as parameter ppSurfaceLevel, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
-    if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
+    if (D3D_OK == hrc) {
        IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppSurfaceLevel);
        IWineD3DSurface_Release(mySurface);
+    } else {
+        WARN("(%p) : Call to IWineD3DTexture_GetSurfaceLevel failed\n", This);
     }
     return hrc;
 }
@@ -244,11 +257,16 @@
     
     TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%ld), Fmt(%u), Pool(%d)\n", This, Width, Height, Levels, Usage, Format,  Pool);
 
+    if (NULL == ppTexture) {
+        WARN("(%p) : Caller passed NULL as parameter ppTexture, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     /* Allocate the storage for the device */
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture9Impl));
 
     if (NULL == object) {
-        FIXME("Allocation of memory failed\n");
+        WARN("Allocation of memory failed\n");
         *ppTexture = NULL;
         return D3DERR_OUTOFVIDEOMEMORY;
     }
@@ -260,7 +278,7 @@
 
     if (FAILED(hrc)) {
         /* free up object */
-        FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
+        WARN("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
         HeapFree(GetProcessHeap(), 0, object);
         *ppTexture = NULL;
    } else {
diff -X ignore -Nruw clean/wine/dlls/d3d9/vertexbuffer.c smallpatches/wine/dlls/d3d9/vertexbuffer.c
--- clean/wine/dlls/d3d9/vertexbuffer.c 2005-08-23 17:05:26.101891560 +0100
+++ smallpatches/wine/dlls/d3d9/vertexbuffer.c 2005-10-12 15:42:50.648274500 +0100
@@ -163,10 +163,15 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hrc = D3D_OK;
 
+    if (NULL == ppVertexBuffer) {
+        WARN("(%p) : Caller passed NULL as parameter ppVertexBuffer, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     /* Allocate the storage for the device */
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer9Impl));
     if (NULL == object) {
-        FIXME("Allocation of memory failed\n");
+        WARN("Allocation of memory failed\n");
         *ppVertexBuffer = NULL;
         return D3DERR_OUTOFVIDEOMEMORY;
     }
@@ -177,7 +182,7 @@
     
     if (hrc != D3D_OK) {
         /* free up object */
-        FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
+        WARN("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
         HeapFree(GetProcessHeap(), 0, object);
         *ppVertexBuffer = NULL;
     } else {
diff -X ignore -Nruw clean/wine/dlls/d3d9/vertexdeclaration.c smallpatches/wine/dlls/d3d9/vertexdeclaration.c
--- clean/wine/dlls/d3d9/vertexdeclaration.c 2005-07-07 21:45:39.000000000 +0100
+++ smallpatches/wine/dlls/d3d9/vertexdeclaration.c 2005-10-12 15:47:04.056111500 +0100
@@ -68,11 +68,17 @@
     HRESULT hr = D3D_OK;
 
     TRACE("(%p) : Relay\n", iface);
+    if (NULL == ppDevice) {
+        WARN("(%p) : Caller passed NULL as parameter ppDevice, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
 
     hr = IWineD3DVertexDeclaration_GetDevice(This->wineD3DVertexDeclaration, &myDevice);
-    if (hr == D3D_OK && myDevice != NULL) {
+    if (D3D_OK == hr) {
         hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
         IWineD3DDevice_Release(myDevice);
+    } else {
+        WARN("(%p) : Call to IWineD3DVertexDeclaration_GetDevice failed\n", This);
     }
     return hr;
 }
@@ -82,6 +88,12 @@
     DWORD NumElements;
     HRESULT hr;
     TRACE("(%p) : Relay\n", iface);
+
+    if (NULL == pNumElements) {
+        WARN("(%p) : Caller passed NULL as parameter pNumElements, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     hr = IWineD3DVertexDeclaration_GetDeclaration(This->wineD3DVertexDeclaration, pDecl, &NumElements);
 
     *pNumElements = NumElements;
@@ -108,13 +120,16 @@
     HRESULT hr = D3D_OK;
 
     TRACE("(%p) : Relay\n", iface);
+
     if (NULL == ppDecl) {
+        WARN("(%p) : Caller passed NULL as parameter ppDecl, returning D3DERR_INVALIDCALL\n", This);
       return D3DERR_INVALIDCALL;
     }
+
     /* Allocate the storage for the device */
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexDeclaration9Impl));
     if (NULL == object) {
-      FIXME("Allocation of memory failed\n");
+        WARN("Allocation of memory failed\n");
       *ppDecl = NULL;
       return D3DERR_OUTOFVIDEOMEMORY;
     }
@@ -125,7 +140,7 @@
 
     if (FAILED(hr)) {
       /* free up object */
-      FIXME("(%p) call to IWineD3DDevice_CreateVertexDeclaration failed\n", This);
+        WARN("(%p) call to IWineD3DDevice_CreateVertexDeclaration failed\n", This);
       HeapFree(GetProcessHeap(), 0, object);
       *ppDecl = NULL;
     } else {
@@ -154,15 +169,16 @@
     TRACE("(%p) : Relay+\n", iface);
 
     if (NULL == ppDecl) {
+        WARN("(%p) : Caller passed NULL as parameter ppDecl, returning D3DERR_INVALIDCALL\n", This);
       return D3DERR_INVALIDCALL;
     }
 
-    *ppDecl = NULL;
     hr = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &pTest);
-    if (hr == D3D_OK && NULL != pTest) {
+    if (D3D_OK == hr) {
         IWineD3DResource_GetParent(pTest, (IUnknown **)ppDecl);
         IWineD3DResource_Release(pTest);
     } else {
+        WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed\n", This);
         *ppDecl = NULL;
     }
     TRACE("(%p) : returning %p\n", This, *ppDecl);
diff -X ignore -Nruw clean/wine/dlls/d3d9/vertexshader.c smallpatches/wine/dlls/d3d9/vertexshader.c
--- clean/wine/dlls/d3d9/vertexshader.c 2005-08-23 17:05:26.105890952 +0100
+++ smallpatches/wine/dlls/d3d9/vertexshader.c 2005-10-12 17:15:14.814763250 +0100
@@ -66,12 +66,21 @@
     IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
     IWineD3DDevice *myDevice = NULL;
     HRESULT hr = D3D_OK;
+
     TRACE("(%p) : Relay\n", This);
 
-    if (D3D_OK == (hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice) && myDevice != NULL)) {
+    if (NULL == ppDevice) {
+        WARN("(%p) : Caller passed NULL as parameter ppDevice, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
+    hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice);
+
+    if (D3D_OK == hr) {
         hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
         IWineD3DDevice_Release(myDevice);
     } else {
+        WARN("(%p) : Call to IWineD3DVertexShader_GetDevice failed\n", This);
         *ppDevice = NULL;
     }
     TRACE("(%p) returing (%p)", This, *ppDevice);
@@ -104,11 +113,16 @@
     HRESULT hrc = D3D_OK;
     IDirect3DVertexShader9Impl *object;
 
+    if (NULL == ppShader) {
+        WARN("(%p) : Caller passed NULL as parameter ppShader, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     /* Setup a stub object for now */
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
     if (NULL == object) {
-        FIXME("Allocation of memory failed\n");
+        WARN("Allocation of memory failed\n");
         *ppShader = NULL;
         return D3DERR_OUTOFVIDEOMEMORY;
     }
@@ -119,7 +133,7 @@
 
     if (FAILED(hrc)) {
         /* free up object */
-        FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
+        WARN("Call to IWineD3DDevice_CreateVertexShader failed\n");
         HeapFree(GetProcessHeap(), 0, object);
         *ppShader = NULL;
     }else{
@@ -133,9 +147,9 @@
 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9 iface, IDirect3DVertexShader9* pShader) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hrc = D3D_OK;
-
+    IDirect3DVertexShader9Impl *shader = (IDirect3DVertexShader9Impl *)pShader;
     TRACE("(%p) : Relay  \n", This);
-    hrc =  IWineD3DDevice_SetVertexShader(This->WineD3DDevice, pShader==NULL?NULL:((IDirect3DVertexShader9Impl *)pShader)->wineD3DVertexShader);
+    hrc =  IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader == NULL ? NULL : shader->wineD3DVertexShader);
 
     TRACE("(%p) : returning hr(%lu) \n", This, hrc);
     return hrc;
@@ -147,8 +161,14 @@
     HRESULT hrc = D3D_OK;
 
     TRACE("(%p) : Relay  device@%p \n", This, This->WineD3DDevice);
+
+    if (NULL == ppShader) {
+        WARN("(%p) : Caller passed NULL as parameter ppShader, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader);
-    if(hrc == D3D_OK){
+    if(D3D_OK == hrc){
        hrc = IWineD3DVertexShader_GetParent(pShader, (IUnknown **)ppShader);
        IWineD3DVertexShader_Release(pShader);
     } else {
diff -X ignore -Nruw clean/wine/dlls/d3d9/volume.c smallpatches/wine/dlls/d3d9/volume.c
--- clean/wine/dlls/d3d9/volume.c 2005-08-23 17:05:26.107890648 +0100
+++ smallpatches/wine/dlls/d3d9/volume.c 2005-10-12 15:53:04.486637000 +0100
@@ -92,19 +92,27 @@
 
 HRESULT WINAPI IDirect3DVolume9Impl_GetContainer(LPDIRECT3DVOLUME9 iface, REFIID riid, void** ppContainer) {
     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
-    HRESULT res;
+    HRESULT hr;
     IUnknown *IWineContainer = NULL;
 
     TRACE("(%p) Relay\n", This);
-    res = IWineD3DVolume_GetContainer(This->wineD3DVolume, riid, (void **)&IWineContainer);
+
+    if (NULL == ppContainer) {
+        WARN("(%p) : Caller passed NULL as parameter ppContainer, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
+    hr = IWineD3DVolume_GetContainer(This->wineD3DVolume, riid, (void **)&IWineContainer);
 
     /* If this works, the only valid container is a child of resource (volumetexture) */
-    if (res == D3D_OK && NULL != ppContainer) {
+    if (D3D_OK == hr) {
         IWineD3DResource_GetParent((IWineD3DResource *)IWineContainer, (IUnknown **)ppContainer);
         IWineD3DResource_Release((IWineD3DResource *)IWineContainer);
+    } else {
+        WARN("(%p) : Call to IWineD3DVolume_GetContainer faile\n", This);
     }
 
-    return res;
+    return hr;
 }
 
 HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(LPDIRECT3DVOLUME9 iface, D3DVOLUME_DESC* pDesc) {
@@ -166,6 +174,11 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)pDevice;
     HRESULT hrc = D3D_OK;
     
+    if (NULL == ppVolume) {
+        WARN("(%p) : Caller passed NULL as parameter ppVolume, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     /* Allocate the storage for the device */
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolume9Impl));
     if (NULL == object) {
diff -X ignore -Nruw clean/wine/dlls/d3d9/volumetexture.c smallpatches/wine/dlls/d3d9/volumetexture.c
--- clean/wine/dlls/d3d9/volumetexture.c 2005-08-23 17:05:26.112889888 +0100
+++ smallpatches/wine/dlls/d3d9/volumetexture.c 2005-10-12 15:55:25.059422250 +0100
@@ -177,10 +177,17 @@
 
     TRACE("(%p) Relay\n", This);
 
+    if (NULL == ppVolumeLevel) {
+        WARN("(%p) : Caller passed NULL as parameter ppVolumeLevel, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     hrc = IWineD3DVolumeTexture_GetVolumeLevel(This->wineD3DVolumeTexture, Level, &myVolume);
-    if (hrc == D3D_OK && NULL != ppVolumeLevel) {
+    if (D3D_OK == hrc) {
        IWineD3DVolumeTexture_GetParent(myVolume, (IUnknown **)ppVolumeLevel);
        IWineD3DVolumeTexture_Release(myVolume);
+    } else {
+        WARN("(%p) : Call to IWineD3DVolumeTexture_GetVolumeLevel failed\n", This);
     }
     return hrc;
 }
@@ -247,10 +254,15 @@
 
     TRACE("(%p) Relay\n", This);
 
+    if (NULL == ppVolumeTexture) {
+        WARN("(%p) : Caller passed NULL as parameter ppVolumeTexture, returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
+    }
+
     /* Allocate the storage for the device */
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolumeTexture9Impl));
     if (NULL == object) {
-        FIXME("(%p) allocation of memory failed\n", This);
+        WARN("(%p) allocation of memory failed\n", This);
         *ppVolumeTexture = NULL;
         return D3DERR_OUTOFVIDEOMEMORY;
     }
@@ -264,7 +276,7 @@
 
     if (hrc != D3D_OK) {
         /* free up object */
-        FIXME("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
+        WARN("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
         HeapFree(GetProcessHeap(), 0, object);
         *ppVolumeTexture = NULL;
     } else {
diff -X ignore -Nruw clean/wine/dlls/d3d9/vshaderdeclaration.c smallpatches/wine/dlls/d3d9/vshaderdeclaration.c
--- clean/wine/dlls/d3d9/vshaderdeclaration.c 2005-03-11 10:25:30.000000000 +0000
+++ smallpatches/wine/dlls/d3d9/vshaderdeclaration.c 1970-01-01 01:00:00.000000000 +0100
@@ -1,74 +0,0 @@
-/*
- * vertex declaration implementation
- *
- * Copyright 2002-2003 Raphael Junqueira
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#include "config.h"
-#include "d3d9_private.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
-
-/**
- * DirectX9 SDK download
- *  http://msdn.microsoft.com/library/default.asp?url=/downloads/list/directx.asp
- *
- * Exploring D3DX
- *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx07162002.asp
- *
- * Using Vertex Shaders
- *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx02192001.asp
- *
- * Dx9 New
- *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/whatsnew.asp
- *
- * Dx9 Shaders
- *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader2_0/VertexShader2_0.asp
- *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader2_0/Instructions/Instructions.asp
- *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/GettingStarted/VertexDeclaration/VertexDeclaration.asp
- *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader3_0/VertexShader3_0.asp
- *
- * Dx9 D3DX
- *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/advancedtopics/VertexPipe/matrixstack/matrixstack.asp
- *
- * FVF
- *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/GettingStarted/VertexFormats/vformats.asp
- *
- * NVIDIA: DX8 Vertex Shader to NV Vertex Program
- *  http://developer.nvidia.com/view.asp?IO=vstovp
- *
- * NVIDIA: Memory Management with VAR
- *  http://developer.nvidia.com/view.asp?IO=var_memory_management 
- */
-
-HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVertexDeclaration(LPDIRECT3DDEVICE9 iface, CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    FIXME("(%p) : stub\n", This);    
-    return D3D_OK;
-}
-
-HRESULT  WINAPI  IDirect3DDevice9Impl_SetVertexDeclaration(LPDIRECT3DDEVICE9 iface, IDirect3DVertexDeclaration9* pDecl) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    FIXME("(%p) : stub\n", This);    
-    return D3D_OK;
-}
-
-HRESULT  WINAPI  IDirect3DDevice9Impl_GetVertexDeclaration(LPDIRECT3DDEVICE9 iface, IDirect3DVertexDeclaration9** ppDecl) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    FIXME("(%p) : stub\n", This);    
-    return D3D_OK;
-}
diff -X ignore -Nruw clean/wine/dlls/wined3d/cubetexture.c smallpatches/wine/dlls/wined3d/cubetexture.c
--- clean/wine/dlls/wined3d/cubetexture.c 2005-08-04 10:16:24.828470144 +0100
+++ smallpatches/wine/dlls/wined3d/cubetexture.c 2005-10-12 14:33:06.666792000 +0100
@@ -261,64 +261,65 @@
 HRESULT WINAPI IWineD3DCubeTextureImpl_GetLevelDesc(IWineD3DCubeTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
     IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
 
-    if (Level < This->baseTexture.levels) {
-        TRACE("(%p) level (%d)\n", This, Level);
-        return IWineD3DSurface_GetDesc(This->surfaces[0][Level], pDesc);
-    }
-    FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
+    WINED3DSURFACE_DESC    wined3ddesc;
+    UINT                   tmpInt = -1;
+
+    TRACE("(%p) Relay\n", This);
+
+    if (NULL == pDesc) {
+        WARN("(%p) : caller sent null for pDesc returning D3DERR_INVALIDCALL\n", This);
     return D3DERR_INVALIDCALL;
 }
+    /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
+    wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
+    wined3ddesc.Type                = &pDesc->Type;
+    wined3ddesc.Usage               = &pDesc->Usage;
+    wined3ddesc.Pool                = &pDesc->Pool;
+    wined3ddesc.Size                = &tmpInt; /* required for d3d8 */
+    wined3ddesc.MultiSampleType     = &pDesc->MultiSampleType;
+    wined3ddesc.MultiSampleQuality  = &pDesc->MultiSampleQuality;
+    wined3ddesc.Width               = &pDesc->Width;
+    wined3ddesc.Height              = &pDesc->Height;
+
+    return IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
+
+}
 
 HRESULT WINAPI IWineD3DCubeTextureImpl_GetCubeMapSurface(IWineD3DCubeTexture *iface, D3DCUBEMAP_FACES FaceType, UINT Level, IWineD3DSurface** ppCubeMapSurface) {
     IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
-    HRESULT hr = D3DERR_INVALIDCALL;
+    HRESULT hr = D3D_OK;
+    IWineD3DSurface *mySurface = NULL;
 
-    if (Level < This->baseTexture.levels) {
-        *ppCubeMapSurface = This->surfaces[FaceType][Level];
-        IWineD3DSurface_AddRef(*ppCubeMapSurface);
-
-        hr = D3D_OK;
+    if (NULL == ppSurfaceLevel) {
+        WARN("(%p) : caller sent null for ppSurfaceLevel returning D3DERR_INVALIDCALL\n", This);
+        return D3DERR_INVALIDCALL;
     }
+
+
+    hr = IWineD3DCubeTextureImpl_GetCubeMapSurface(This->wineD3DCubeTexture, FaceType, Level, &mySurface);
+
     if (D3D_OK == hr) {
-        TRACE("(%p) -> faceType(%d) level(%d) returning surface@%p \n", This, FaceType, Level, This->surfaces[FaceType][Level]);
+       IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppSurfaceLevel);
+       IWineD3DSurface_Release(mySurface);
     } else {
-        WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
+        WARN("(%p) : Call to IWineD3DCubeTextureImpl_GetCubeMapSurface failed \n", This);
     }
 
     return hr;
 }
 
 HRESULT WINAPI IWineD3DCubeTextureImpl_LockRect(IWineD3DCubeTexture *iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
-    HRESULT hr = D3DERR_INVALIDCALL;
     IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
 
-    if (Level < This->baseTexture.levels) {
-        hr = IWineD3DSurface_LockRect(This->surfaces[FaceType][Level], pLockedRect, pRect, Flags);
-    }
-
-    if (D3D_OK == hr) {
-        TRACE("(%p) -> faceType(%d) level(%d) returning memory@%p success(%lu)\n", This, FaceType, Level, pLockedRect->pBits, hr);
-    } else {
-        WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
-    }
-
-    return hr;
+    TRACE("(%p) Relay\n", This);
+    return IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, FaceType, Level, pLockedRect, pRect, Flags);
 }
 
 HRESULT WINAPI IWineD3DCubeTextureImpl_UnlockRect(IWineD3DCubeTexture *iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
-    HRESULT hr = D3DERR_INVALIDCALL;
     IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
 
-    if (Level < This->baseTexture.levels) {
-        hr = IWineD3DSurface_UnlockRect(This->surfaces[FaceType][Level]);
-    }
-
-    if (D3D_OK == hr) {
-        TRACE("(%p) -> faceType(%d) level(%d) success(%lu)\n", This, FaceType, Level, hr);
-    } else {
-        WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
-    }
-    return hr;
+    TRACE("(%p) Relay\n", This);
+    return IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, FaceType, Level);
 }
 
 HRESULT