Archived

This topic is now archived and is closed to further replies.

88er

D3DDevice object is still referenced!

Recommended Posts

windows2000 + sp4 + VC6 + dx8sdk ----------------------------------------------- The program report the error: ******************************** Direct3D8: (ERROR) :Memory still allocated! Alloc count = 144 ...... Direct3D8: (ERROR) :Memory Address: 027cb32c lAllocID=491 dwSize=00000030, ReturnAddr=016c246b (pid=000014d4) Direct3D8: (ERROR) :Memory Address: 027cb394 lAllocID=492 dwSize=00000030, ReturnAddr=016c47bf (pid=000014d4) Direct3D8: (ERROR) :Total Memory Unfreed From Current Process = 963415 bytes ------------------------------------------------ I didn''t know when should i release the d3ddevice besides the program end,and which operation will be call d3ddevice.AddRef. thx a lot.

Share this post


Link to post
Share on other sites
Hi
When you create a texture with D3DXCreateTextureFromFile() for instance, it allocates memory for a IDirect3DTexture8 object, hence doing a ''new'' and a AddRef() but we dont give a **** about that one .Be sure to match each such function with a call to Release() (use the SAFE_RELEASE() macro , it helps a lot !).
Remember that when you change the device (going from windowed to fullscreen for instance) you must delete ALL device-dependant objects (textures, vertex buffers, index buffers and so on)
When you resize the device, a call to IDirect3DDevice8::Reset() is performed and you need to cleanup objects created in the D3DPOOL_DEFAULT (is is D3DPOOL_MANAGED ? not sure ...), which includes index buffers, and other funny things.
If you are using AppWizard:
- all objects created in InitDeviceObjects() must be released in DeleteDeviceObjects()
- all objects created in RestoreDeviceObjects() must be released in InvalidateDeviceObjects()

Share this post


Link to post
Share on other sites
Well, get a memory manager to help you out. Try Midnignt''s memory manager here. Now, every time you forget to deallocate something, you''ll get an exact file and line number to help you out. But remember, you DON''T call AddRef() on a DirectX object at ANY time, because when you create a DirectX object, a reference is automatically added anyway. Therefore, you should only release a DirectX device or main object and that you should only do at the end of your program (or when one of the special events occurs, such as device reset, fullscreen<->window, etc.). Good Luck

Share this post


Link to post
Share on other sites