Commit 35dd693a authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

d3d9: Fix the circular converted vertex declaration reference.

parent 2db7691e
...@@ -62,8 +62,7 @@ static ULONG WINAPI IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9 iface) { ...@@ -62,8 +62,7 @@ static ULONG WINAPI IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9 iface) {
if (ref == 0) { if (ref == 0) {
This->inDestruction = TRUE; This->inDestruction = TRUE;
if (This->convertedDecl != NULL) IDirect3DDevice9_SetVertexDeclaration(iface, NULL);
IUnknown_Release(This->convertedDecl);
IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroyDepthStencilSurface, D3D9CB_DestroySwapChain); IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroyDepthStencilSurface, D3D9CB_DestroySwapChain);
IWineD3DDevice_Release(This->WineD3DDevice); IWineD3DDevice_Release(This->WineD3DDevice);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
...@@ -784,14 +783,14 @@ HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9 iface, DWORD FVF) ...@@ -784,14 +783,14 @@ HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9 iface, DWORD FVF)
hr = IDirect3DDevice9Impl_CreateVertexDeclaration(iface, elements, &pDecl); hr = IDirect3DDevice9Impl_CreateVertexDeclaration(iface, elements, &pDecl);
if (hr != S_OK) goto exit; if (hr != S_OK) goto exit;
hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, pDecl); hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, pDecl);
if (hr != S_OK) goto exit; if (hr != S_OK) goto exit;
This->convertedDecl = pDecl; This->convertedDecl = pDecl;
pDecl = NULL;
exit: exit:
HeapFree(GetProcessHeap(), 0, elements); HeapFree(GetProcessHeap(), 0, elements);
/* If allocated and set correctly, this will reduce the refcount to 0, but not destroy the declaration */
if (pDecl) IUnknown_Release(pDecl); if (pDecl) IUnknown_Release(pDecl);
if (hr != S_OK) return hr; if (hr != S_OK) return hr;
} }
......
...@@ -259,11 +259,6 @@ static void lighting_test(IDirect3DDevice9 *device) ...@@ -259,11 +259,6 @@ static void lighting_test(IDirect3DDevice9 *device)
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE); hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr)); ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr));
/* Hack for a bug in d3d9: SetFVF creates a converted vertex declaration, with a circular refcount.
* This prevents the screen resolution from being restored correctly on device release. Unset the vdecl
*/
IDirect3DDevice9_SetVertexDeclaration(device, NULL);
} }
static void clear_test(IDirect3DDevice9 *device) static void clear_test(IDirect3DDevice9 *device)
...@@ -547,8 +542,6 @@ static void fog_test(IDirect3DDevice9 *device) ...@@ -547,8 +542,6 @@ static void fog_test(IDirect3DDevice9 *device)
/* Turn off the fog master switch to avoid confusing other tests */ /* Turn off the fog master switch to avoid confusing other tests */
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, FALSE); hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
ok(hr == D3D_OK, "Turning off fog calculations returned %s\n", DXGetErrorString9(hr)); ok(hr == D3D_OK, "Turning off fog calculations returned %s\n", DXGetErrorString9(hr));
IDirect3DDevice9_SetVertexDeclaration(device, NULL);
} }
/* This test verifies the behaviour of cube maps wrt. texture wrapping. /* This test verifies the behaviour of cube maps wrt. texture wrapping.
......
...@@ -216,10 +216,15 @@ static ULONG WINAPI IDirect3DVertexDeclaration9Impl_Release(LPDIRECT3DVERTEXDECL ...@@ -216,10 +216,15 @@ static ULONG WINAPI IDirect3DVertexDeclaration9Impl_Release(LPDIRECT3DVERTEXDECL
TRACE("(%p) : ReleaseRef to %d\n", This, ref); TRACE("(%p) : ReleaseRef to %d\n", This, ref);
if (ref == 0) { if (ref == 0) {
IWineD3DVertexDeclaration_Release(This->wineD3DVertexDeclaration); IDirect3DDevice9 *parentDevice = This->parentDevice;
IUnknown_Release(This->parentDevice); BOOL converted = ((IDirect3DDevice9Impl *) parentDevice)->convertedDecl == iface;
HeapFree(GetProcessHeap(), 0, This->elements);
HeapFree(GetProcessHeap(), 0, This); if(!converted) {
IWineD3DVertexDeclaration_Release(This->wineD3DVertexDeclaration);
HeapFree(GetProcessHeap(), 0, This->elements);
HeapFree(GetProcessHeap(), 0, This);
}
IUnknown_Release(parentDevice);
} }
return ref; return ref;
} }
...@@ -367,12 +372,17 @@ HRESULT WINAPI IDirect3DDevice9Impl_SetVertexDeclaration(LPDIRECT3DDEVICE9 ifa ...@@ -367,12 +372,17 @@ HRESULT WINAPI IDirect3DDevice9Impl_SetVertexDeclaration(LPDIRECT3DDEVICE9 ifa
TRACE("(%p) : Relay\n", iface); TRACE("(%p) : Relay\n", iface);
if (This->convertedDecl && This->convertedDecl != pDecl) { if (This->convertedDecl && This->convertedDecl != pDecl) {
IUnknown_Release(This->convertedDecl); IDirect3DVertexDeclaration9Impl *iDecl = (IDirect3DVertexDeclaration9Impl *) This->convertedDecl;
/* Will need locking once we claim to be thread safe */
if(iDecl->ref == 0) {
IUnknown_AddRef(This->convertedDecl);
IUnknown_Release(This->convertedDecl);
}
This->convertedDecl = NULL; This->convertedDecl = NULL;
} }
hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, pDeclImpl == NULL ? NULL : pDeclImpl->wineD3DVertexDeclaration); hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, pDeclImpl == NULL ? NULL : pDeclImpl->wineD3DVertexDeclaration);
return hr; return hr;
} }
......
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