d3d8: Don't release the parent device before destroying its children.
authorAllan Tong <actong88@gmail.com>
Mon, 28 Sep 2009 16:50:15 +0000 (12:50 -0400)
committerAlexandre Julliard <julliard@winehq.org>
Tue, 29 Sep 2009 10:05:53 +0000 (12:05 +0200)
dlls/d3d8/cubetexture.c
dlls/d3d8/indexbuffer.c
dlls/d3d8/surface.c
dlls/d3d8/texture.c
dlls/d3d8/vertexbuffer.c
dlls/d3d8/volumetexture.c

index d3ec98c1330addc8f3dcc5d937c01d2241e6917d..24417df6cf3174f1a1a9d9b4919ecadc9b46b085 100644 (file)
@@ -64,12 +64,16 @@ static ULONG WINAPI IDirect3DCubeTexture8Impl_Release(LPDIRECT3DCUBETEXTURE8 ifa
     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
 
     if (ref == 0) {
+        IDirect3DDevice8 *parentDevice = This->parentDevice;
+
         TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
 
-        IUnknown_Release(This->parentDevice);
         wined3d_mutex_lock();
         IWineD3DCubeTexture_Release(This->wineD3DCubeTexture);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice8_Release(parentDevice);
     }
     return ref;
 }
index 49391222663a116b829685c271a6ea3b2f4731b3..bb62c39a3764e35d47d90f76043d0855bdef4001 100644 (file)
@@ -64,10 +64,14 @@ static ULONG WINAPI IDirect3DIndexBuffer8Impl_Release(LPDIRECT3DINDEXBUFFER8 ifa
     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
 
     if (ref == 0) {
-        IDirect3DDevice8_Release(This->parentDevice);
+        IDirect3DDevice8 *parentDevice = This->parentDevice;
+
         wined3d_mutex_lock();
         IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice8_Release(parentDevice);
     }
     return ref;
 }
index 2d00fce822c49717a627551f979ff721841592a2..8923dd8b7ef80fe15d823426094639b7f4b907e0 100644 (file)
@@ -79,11 +79,14 @@ static ULONG WINAPI IDirect3DSurface8Impl_Release(LPDIRECT3DSURFACE8 iface) {
         TRACE("(%p) : ReleaseRef to %d\n", This, ref);
 
         if (ref == 0) {
-            if (This->parentDevice) IUnknown_Release(This->parentDevice);
+            IDirect3DDevice8 *parentDevice = This->parentDevice;
+
             /* Implicit surfaces are destroyed with the device, not if refcount reaches 0. */
             wined3d_mutex_lock();
             IWineD3DSurface_Release(This->wineD3DSurface);
             wined3d_mutex_unlock();
+
+            if (parentDevice) IDirect3DDevice8_Release(parentDevice);
         }
 
         return ref;
index e377fffec69919bfef92f3f53c2878f59b585238..000b07858dd40cd882d7812193d3972848bbe263 100644 (file)
@@ -65,10 +65,14 @@ static ULONG WINAPI IDirect3DTexture8Impl_Release(LPDIRECT3DTEXTURE8 iface) {
     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
 
     if (ref == 0) {
-        IDirect3DDevice8_Release(This->parentDevice);
+        IDirect3DDevice8 *parentDevice = This->parentDevice;
+
         wined3d_mutex_lock();
         IWineD3DTexture_Release(This->wineD3DTexture);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice8_Release(parentDevice);
     }
     return ref;
 }
index 99e8304ecd2e2c54cd045fbea21e6df4bd809f53..a798afd829b0e4674ff562256143e6ed669fc058 100644 (file)
@@ -65,10 +65,14 @@ static ULONG WINAPI IDirect3DVertexBuffer8Impl_Release(LPDIRECT3DVERTEXBUFFER8 i
     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
 
     if (ref == 0) {
-        IDirect3DDevice8_Release(This->parentDevice);
+        IDirect3DDevice8 *parentDevice = This->parentDevice;
+
         wined3d_mutex_lock();
         IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice8_Release(parentDevice);
     }
 
     return ref;
index 46c1ec5af836d9f030fdaf5577d804f5d0222def..d31c1561e0d3aa75c1447ea57edbe263bf9cc06c 100644 (file)
@@ -65,10 +65,14 @@ static ULONG WINAPI IDirect3DVolumeTexture8Impl_Release(LPDIRECT3DVOLUMETEXTURE8
     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
 
     if (ref == 0) {
-        IUnknown_Release(This->parentDevice);
+        IDirect3DDevice8 *parentDevice = This->parentDevice;
+
         wined3d_mutex_lock();
         IWineD3DVolumeTexture_Release(This->wineD3DVolumeTexture);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice8_Release(parentDevice);
     }
     return ref;
 }