Shut-Down Direct-Turd!
I'm a newbie to Direct3D programming so please be kind. My problem is that I have a program which just plots a bunch of vertices from a text file. The problem isn't getting it to run, but the shut down. I continually get an error when the program closes. Saying Unhandled Exception: some number. When I take away the line to release the Direct3DDevice, I don't get this error. I wouldn't release it, but I don't want a memory leak. Is this not supposed to be released? Am I doing something wrong? Here is my intialization:
hresult = DirectDrawCreateEx(NULL, (VOID**)&lpdd, IID_IDirectDraw7, NULL);
lpdd->SetCooperativeLevel( hwnd,DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT);
lpdd->SetDisplayMode(1024,768,32,0,0);
ZeroMemory ( &ddsd, sizeof(DDSURFACEDESC2));
ddsd.dwSize=sizeof(DDSURFACEDESC2);
ddsd.dwFlags=DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY;
ddsd.dwBackBufferCount=1;
lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL);
ddscaps.dwCaps=DDSCAPS_BACKBUFFER;
ZeroMemory ( &ddsd, sizeof(DDSURFACEDESC2));
ddsd.dwSize=sizeof(DDSURFACEDESC2);
ddscaps.dwCaps=DDSCAPS_BACKBUFFER;
lpddsprimary->GetAttachedSurface(&ddscaps,&lpddssecondary);
ZeroMemory ( &ddsd, sizeof(DDSURFACEDESC2));
ddsd.dwFlags= DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;
ddsd.dwWidth=1024;
ddsd.dwHeight=768;
ddsd.ddpfPixelFormat.dwSize= sizeof( DDPIXELFORMAT);
ddsd.ddpfPixelFormat.dwFlags=DDPF_ZBUFFER;
ddsd.ddpfPixelFormat.dwZBufferBitDepth=24;
ddsd.ddpfPixelFormat.dwZBitMask=0xFFFFFF;
lpdd->CreateSurface ( &ddsd, &zbuffer, NULL);
lpddssecondary->AddAttachedSurface(zbuffer);
lpdd->QueryInterface ( IID_IDirect3D7, ( void ** ) &Direct3D7 );
Direct3D7->CreateDevice ( IID_IDirect3DHALDevice, lpddssecondary, &Direct3DDevice7 );
Which is just mainly a Primary Surface, Secondary Surface(Backbuffer), and the Z buffer
Here is my shutdown:
if (Direct3D7)
Direct3D7->Release();
if (zbuffer)
zbuffer->Release();
if (lpddssecondary)
lpddssecondary->Release();
if (lpddsprimary)
lpddsprimary->Release();
if( Direct3DDevice7)
if( 0 < Direct3DDevice7->Release() )
return E_FAIL;
if( lpdd )
if( 0 < lpdd->Release() )
return E_FAIL;
zbuffer=NULL;
lpddssecondary=NULL;
lpddsprimary=NULL;
lpdd=NULL;
Direct3D7=NULL;
Taking away the Release of the Direct3DDevice makes the program run as slick as snot on a door knob. Any help would be appreciated!
Edited by - Wavewash on 8/19/00 7:32:08 AM
Your releasing the DIrectDraw/Direct3D interfaces in the wrong order.
Remember that you should release all DirectX interfaces in the reverse order you created them.
Remember that you should release all DirectX interfaces in the reverse order you created them.
Thankyou Mr.Cucumber, I went back and checked an checked my code to make sure that I released everything in order. But the real problem was that for some reason, after it went to destroy the window, It returned to my rendering loop. I fixed the problem with a simple if statement around the rendering loop that checked to see if the the direct3ddevice refrence count was equal to 0.
Here is the if I added
if (Direct3DDevice7>0)
Hope this saves someone some time. I spent three days on this problem. At last I can sleep easy. Thanks again. Cucumber!
Here is the if I added
if (Direct3DDevice7>0)
Hope this saves someone some time. I spent three days on this problem. At last I can sleep easy. Thanks again. Cucumber!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement