DDraw: Remove the process counter

Stefan Dösinger stefandoesinger at gmx.at
Mon Oct 9 08:29:05 CDT 2006


This is not needed because PROCESS_ATTACH/DETACH are used, there will be only 
one attachment
-------------- next part --------------
From da5b6fdb4479624566b3d488824f76e381ae4a6c Mon Sep 17 00:00:00 2001
From: Stefan Doesinger <stefan at codeweavers.com>
Date: Mon, 9 Oct 2006 15:19:47 +0200
Subject: [PATCH] DDraw: Remove the process counter
---
 dlls/ddraw/main.c |  114 +++++++++++++++++++++++++----------------------------
 1 files changed, 53 insertions(+), 61 deletions(-)

diff --git a/dlls/ddraw/main.c b/dlls/ddraw/main.c
index 7afe210..6778c57 100644
--- a/dlls/ddraw/main.c
+++ b/dlls/ddraw/main.c
@@ -812,8 +812,6 @@ DllMain(HINSTANCE hInstDLL,
         DWORD Reason,
         void *lpv)
 {
-    static LONG counter = 0;
-
     TRACE("(%p,%lx,%p)\n", hInstDLL, Reason, lpv);
     if (Reason == DLL_PROCESS_ATTACH)
     {
@@ -865,73 +863,67 @@ DllMain(HINSTANCE hInstDLL,
         }
 
         DisableThreadLibraryCalls(hInstDLL);
-        TRACE("Attach counter: %ld\n", InterlockedIncrement(&counter));
     }
     else if (Reason == DLL_PROCESS_DETACH)
     {
-        TRACE("Attach counter: %ld\n", InterlockedDecrement(&counter));
-
-        if(counter == 0)
+        if(!list_empty(&global_ddraw_list))
         {
-            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;
-                WARN("There are still existing DirectDraw interfaces. Wine bug or buggy application?\n");
+                HRESULT hr;
+                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 */
-                LIST_FOR_EACH_SAFE(entry, entry2, &global_ddraw_list)
+                /* 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++)
                 {
-                    HRESULT hr;
-                    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)));
-                    }
-
-                    /* 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)));
+                    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)));
             }
         }
     }
-- 
1.4.1.1



More information about the wine-patches mailing list