Skip to main content
gamedev.net
🔒 Locked

DirectX Debugger -- Memory

Started by ms291052 Apr 24, 2004 at 3:13 PM 2 replies 500+ views
Original Post
ms291052
ms291052
I went to debug my application and the debugger told me I had nine objects still allocated in memory. Fine, I go to my DX thing and break on AllocID, and put in each AllocID from the debug spew. Now, I did this for each unique AllocID (of which there were five), and they all only pointed to two lines, both in my init function, however I thought I was deleting them all in my cleanup function. Take a look at the following. Debug Spew: (line of code appended after each line)
Direct3D9: (ERROR) :Memory Address: 0039b3dc lAllocID=11 dwSize=00000140, ReturnAddr=03872f45 (pid=00000fe4) -- g_pD3D = Direct3DCreate9( D3D_SDK_VERSION );
Direct3D9: (ERROR) :Memory Address: 0039b3dc lAllocID=11 dwSize=00000140, ReturnAddr=03872f45 (pid=00000fe4) -- Same As Above
Direct3D9: (ERROR) :Memory Address: 0039b3dc lAllocID=11 dwSize=00000140, ReturnAddr=03872f45 (pid=00000fe4) -- Same As Above
Direct3D9: (ERROR) :Memory Address: 003996ac lAllocID=22 dwSize=00001008, ReturnAddr=0387478b (pid=00000fe4) -- g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE , &g_d3dpp, &g_pd3dDevice );
Direct3D9: (ERROR) :Memory Address: 0039a784 lAllocID=24 dwSize=00000008, ReturnAddr=038748bc (pid=00000fe4) -- Same As Above
Direct3D9: (ERROR) :Memory Address: 0039a784 lAllocID=24 dwSize=00000008, ReturnAddr=038748bc (pid=00000fe4) -- Same As Above
Direct3D9: (ERROR) :Memory Address: 0039ea6c lAllocID=27 dwSize=00000198, ReturnAddr=03873796 (pid=00000fe4) -- Same As Above
Direct3D9: (ERROR) :Memory Address: 0039ec2c lAllocID=28 dwSize=00000030, ReturnAddr=03873796 (pid=00000fe4) -- Same As Above
Direct3D9: (ERROR) :Memory Address: 0039ec2c lAllocID=28 dwSize=00000030, ReturnAddr=03873796 (pid=00000fe4) -- Same As Above
Init Function:
HRESULT InitD3DWin( HWND hWnd )
{
    g_pD3D = Direct3DCreate9( D3D_SDK_VERSION );
    ZeroMemory( &g_d3dpp, sizeof(g_d3dpp) );
    g_d3dpp.Windowed = TRUE;
	g_d3dpp.EnableAutoDepthStencil = TRUE;
	g_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    g_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	g_d3dpp.BackBufferWidth        = DEVICEWIDTH;
	g_d3dpp.BackBufferHeight       = DEVICEHEIGHT;
    g_d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
    g_d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
	g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
	g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE , &g_d3dpp, &g_pd3dDevice );

	OneTimeSceneInit();
    return S_OK;
}
Cleanup Function:
#define SAFE_RELEASE(p) if(p != NULL){(p)->Release();(p)=NULL;}
void Cleanup()
{
     //...

    SAFE_RELEASE(g_pd3dDevice);
	SAFE_RELEASE(g_pD3D);
}
WinMain:
int WINAPI WinMain( HINSTANCE hinst, HINSTANCE, LPSTR, int )
{	
	//CreateWindow

    if( SUCCEEDED( InitD3DWin( hWnd) ) )
    {
	if( SUCCEEDED( InitGeometry() ) )
        {
            ShowWindow( hWnd, SW_SHOWDEFAULT );
            UpdateWindow( hWnd );
            MSG msg;
            ZeroMemory( &msg, sizeof(msg) );
			while( msg.message!=WM_QUIT )
            {
				if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
				{
					TranslateMessage( &msg );
					DispatchMessage( &msg );
				}
				else
				{
					Render();
				}
            }
        }
    }
	Cleanup();
    //ReleaseWindow

    return 0;
}
So... This leads me to three questions: 1) Does it mean anything that different AllocID id''s point to the same line? 2) What does it mean that the same AllocID and (apparently) same object is shown twice? 3) What could possibly be going wrong? Is D3D definately pointing me to the right place? Thanks for all your time and thought, ms
superpig
superpig
Don't forget that D3D objects have their own, internal dependencies; for example, the D3D object was probably still alive due to a reference in the Device object.

The latter is the one you want to look at, I think. Almost any object in Direct3D keeps a reference to the Device object. So it could even be another object - like a texture - that you've not released.

Are you sure that all the messages after the Device one are "Same As Above?" None of them have the same alloc ID or return address.

[Edit: OK, didn't read the end of your message properly. I've never really understood those messages in the debug spew so my comment won't have been much help. The point about other objects 'keeping the device alive' still stands though.]

[edited by - Superpig on April 24, 2004 8:06:09 PM]
Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse
reaptide
reaptide
To add on to what superpig stated.

The Release method will return the reference count of the object being released. Using that you can quickly tell if there are other objects still referencing the object you want to release.

If the reference count is greater than zero then you missed something.
Muhammad Haggag
Muhammad Haggag
Use smart COM pointers, and forget about this forever. For example, CComPtr (in <atlbase.h> )

Muhammad Haggag,
Optimize
Bitwise account: MHaggag -
[edit]Angle brackets fix

[edited by - Coder on April 24, 2004 12:27:54 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.