DD_Shutdown

Started by
14 comments, last by jtecin 24 years, 4 months ago
Try

int GFX_Shutdown(void)
{
if (lpddsback)
lpddsback->Release(); lpddsback=0;
if (lpddsprimary)
lpddsprimary->Release();lpddsprimary=0;
if (lpdd)
lpdd->Release();lpdd=0;
return 0;
}

------------------
Dance with me......

http://members.xoom.com/CJdeVos/index.htm

Advertisement
I can't see that doing this would be any different but from memory I always use:

if (lpddsback!=null){
lpddsback->Release();
lpddsback=null;
}

Most likly overkill on my part but I have never had any problems with it.

I've read, that if you release the DDraw-Object, the surfaces are released automatically.

I think a problem like this was mentioned in the MS DirectX FAQ at http://www.microsoft.com/directx

i'm guessing your situation is using complex
which means when you kill the primary surface the release function for the attached back buffer gets called and so what may be going on is that you are first killing the back buffer but then you kill the primary buffer and it tries to release the back buffer again which is killed aand uh oh bad bad bad
your order of killing stuff is fine you jsut needed to point everything to NULL after killing it like the above posts say
Look in the DX docs (I'm assuming you're using DX 7.0) under "When Reference Counts Will Change" and "Reference Counts for Complex Surfaces", and "Releasing Surfaces". In short, I think if you just create the flipping chain using create surface, you can release the whole thing by just releasing the primary surface. However if you get access to the back buffer by using GetAttachedSurface (which you probably do, I dont know how else you can do it!), you have to release the back buffer explicitly because GetAttachedSurface increases its ref count.
I think setting them to NULL after the release is a good idea, but it would only find bugs from your own code trying to reuse the object.
One thing you might consider doing is watching the ref count of both surfaces as your program progresses and terminates - just write something like:
int refcount;
Surf->AddRef();
refcount = (int) Surf->Release();
This should give you the current reference count without actually changing it, and you can see what is actually going on.
Finally, IDirectDraw and IDirectDraw2 interfaces, when released, also release all their children, wheras later interfaces don't, but this shouldn't be a problem for you because you are releasing the DD object last (the problem was with releasing children after the parent)
Hope this helps a little
-ns

[This message has been edited by NightShade (edited December 23, 1999).]

-ns-
Don't release the backbuffer if it's an attached surface. Just release the primary and it should release all surfaces attached to it.

You can test it out by releasing the primary surface, then try accessing the backbuffer - it should fail since it too was released.


Jim Adams

Okay, I've tried everything but still no luck. FYI I am using DX 5.0 with VC++ 4.0(I know it is kind of out of date but can't afford anything else right now). Anyway, I thought I'd post the code for my GFX_init function:

int GFX_Init()
{
//Create DirectDraw object
if(DirectDrawCreate(NULL, &lpdd, NULL) != DD_OK)
{
MessageBox(main_window_handle,"Could Not Create Direct Draw","Error!",MB_OK);
return 0;
}
//Get exclusive mode but still allow ctrl & alt & delete
if(lpdd->SetCooperativeLevel(main_window_handle, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT) != DD_OK)
{
MessageBox(main_window_handle,"Could Not Set ddraw cooperative","Error!",MB_OK);
return 0;
}
//Set the video mode to 640x460x16
if(lpdd->SetDisplayMode(640, 480, 16) != DD_OK)
{
MessageBox(main_window_handle,"Could Not set display mode","Error!",MB_OK);
return 0;
}
//Create the primary surface with a back buffer, make it "flipable"
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;
if(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL) != DD_OK) return 0;

ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
if(lpddsprimary->GetAttachedSurface(&ddscaps, &lpddsback) != DD_OK) return 0;

return 1; //Return success!
}

Clear the ddsd structure in there:

memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
...


If that doesn't help, what exactly is happening when you exit? That compiler/dx version is fine - that's what I use on one of my systems.

Jim Adams

When I try to exit, I get the usual windows "error beep", and black covers most of the screen except for a little on the right and bottom. The only way to get out is by using CTRL+ALT+DELETE and clicking on VC++ and END TASK. Ne1 know what's going on?
Now I am wondering how your Window Procedure looks like

You should first release all your ddraw stuff, then call PostQuitMessage(0) or whatever......and then break.

Done that?

------------------
Dance with me......

http://members.xoom.com/CJdeVos/index.htm

This topic is closed to new replies.

Advertisement