Commit 4ff712c9 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

ddraw: Remove the process counter.

parent 3543a070
...@@ -812,8 +812,6 @@ DllMain(HINSTANCE hInstDLL, ...@@ -812,8 +812,6 @@ DllMain(HINSTANCE hInstDLL,
DWORD Reason, DWORD Reason,
void *lpv) void *lpv)
{ {
static LONG counter = 0;
TRACE("(%p,%lx,%p)\n", hInstDLL, Reason, lpv); TRACE("(%p,%lx,%p)\n", hInstDLL, Reason, lpv);
if (Reason == DLL_PROCESS_ATTACH) if (Reason == DLL_PROCESS_ATTACH)
{ {
...@@ -865,73 +863,67 @@ DllMain(HINSTANCE hInstDLL, ...@@ -865,73 +863,67 @@ DllMain(HINSTANCE hInstDLL,
} }
DisableThreadLibraryCalls(hInstDLL); DisableThreadLibraryCalls(hInstDLL);
TRACE("Attach counter: %ld\n", InterlockedIncrement(&counter));
} }
else if (Reason == DLL_PROCESS_DETACH) else if (Reason == DLL_PROCESS_DETACH)
{ {
TRACE("Attach counter: %ld\n", InterlockedDecrement(&counter)); if(!list_empty(&global_ddraw_list))
if(counter == 0)
{ {
if(!list_empty(&global_ddraw_list)) struct list *entry, *entry2;
WARN("There are still existing DirectDraw interfaces. Wine bug or buggy application?\n");
/* We remove elemets from this loop */
LIST_FOR_EACH_SAFE(entry, entry2, &global_ddraw_list)
{ {
struct list *entry, *entry2; HRESULT hr;
WARN("There are still existing DirectDraw interfaces. Wine bug or buggy application?\n"); DDSURFACEDESC2 desc;
int i;
IDirectDrawImpl *ddraw = LIST_ENTRY(entry, IDirectDrawImpl, ddraw_list_entry);
WARN("DDraw %p has a refcount of %ld\n", ddraw, ddraw->ref7 + ddraw->ref4 + ddraw->ref2 + ddraw->ref1);
/* Add references to each interface to avoid freeing them unexpectadely */
IDirectDraw_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw));
IDirectDraw2_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw2));
IDirectDraw4_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw4));
IDirectDraw7_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw7));
/* Does a D3D device exist? Destroy it
* TODO: Destroy all Vertex buffers, Lights, Materials
* and execture buffers too
*/
if(ddraw->d3ddevice)
{
WARN("DDraw %p has d3ddevice %p attached\n", ddraw, ddraw->d3ddevice);
while(IDirect3DDevice7_Release(ICOM_INTERFACE(ddraw->d3ddevice, IDirect3DDevice7)));
}
/* We remove elemets from this loop */ /* Try to release the objects
LIST_FOR_EACH_SAFE(entry, entry2, &global_ddraw_list) * Do an EnumSurfaces to find any hanging surfaces
*/
memset(&desc, 0, sizeof(desc));
desc.dwSize = sizeof(desc);
for(i = 0; i <= 1; i++)
{ {
HRESULT hr; hr = IDirectDraw7_EnumSurfaces(ICOM_INTERFACE(ddraw, IDirectDraw7),
DDSURFACEDESC2 desc; DDENUMSURFACES_ALL,
int i; &desc,
IDirectDrawImpl *ddraw = LIST_ENTRY(entry, IDirectDrawImpl, ddraw_list_entry); (void *) ddraw,
DestroyCallback);
WARN("DDraw %p has a refcount of %ld\n", ddraw, ddraw->ref7 + ddraw->ref4 + ddraw->ref2 + ddraw->ref1); if(hr != D3D_OK)
ERR("(%p) EnumSurfaces failed, prepare for trouble\n", ddraw);
/* Add references to each interface to avoid freeing them unexpectadely */
IDirectDraw_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw));
IDirectDraw2_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw2));
IDirectDraw4_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw4));
IDirectDraw7_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw7));
/* Does a D3D device exist? Destroy it
* TODO: Destroy all Vertex buffers, Lights, Materials
* and execture buffers too
*/
if(ddraw->d3ddevice)
{
WARN("DDraw %p has d3ddevice %p attached\n", ddraw, ddraw->d3ddevice);
while(IDirect3DDevice7_Release(ICOM_INTERFACE(ddraw->d3ddevice, IDirect3DDevice7)));
}
/* Try to release the objects
* Do an EnumSurfaces to find any hanging surfaces
*/
memset(&desc, 0, sizeof(desc));
desc.dwSize = sizeof(desc);
for(i = 0; i <= 1; i++)
{
hr = IDirectDraw7_EnumSurfaces(ICOM_INTERFACE(ddraw, IDirectDraw7),
DDENUMSURFACES_ALL,
&desc,
(void *) ddraw,
DestroyCallback);
if(hr != D3D_OK)
ERR("(%p) EnumSurfaces failed, prepare for trouble\n", ddraw);
}
/* Check the surface count */
if(ddraw->surfaces > 0)
ERR("DDraw %p still has %ld surfaces attached\n", ddraw, ddraw->surfaces);
/* Release all hanging references to destroy the objects. This
* restores the screen mode too
*/
while(IDirectDraw_Release(ICOM_INTERFACE(ddraw, IDirectDraw)));
while(IDirectDraw2_Release(ICOM_INTERFACE(ddraw, IDirectDraw2)));
while(IDirectDraw4_Release(ICOM_INTERFACE(ddraw, IDirectDraw4)));
while(IDirectDraw7_Release(ICOM_INTERFACE(ddraw, IDirectDraw7)));
} }
/* Check the surface count */
if(ddraw->surfaces > 0)
ERR("DDraw %p still has %ld surfaces attached\n", ddraw, ddraw->surfaces);
/* Release all hanging references to destroy the objects. This
* restores the screen mode too
*/
while(IDirectDraw_Release(ICOM_INTERFACE(ddraw, IDirectDraw)));
while(IDirectDraw2_Release(ICOM_INTERFACE(ddraw, IDirectDraw2)));
while(IDirectDraw4_Release(ICOM_INTERFACE(ddraw, IDirectDraw4)));
while(IDirectDraw7_Release(ICOM_INTERFACE(ddraw, IDirectDraw7)));
} }
} }
} }
......
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