D3D Memory Leak.. with smart pointers?

Started by
11 comments, last by Fuzztrek 20 years, 2 months ago
I know this thread is old, but hopefully you still frequent this board Fuzztrek, and just in case anyone else needs to know the answer to this.

I had this same problem when intializing D3D you probably have a line like this somewhere:

m_pD3D = Direct3DCreate9(D3D_SDK_VERSION)

where m_pD3D is declared as (I do it this way) CComPtr{IDirect3D9} m_pD3D (replace the brackets with less then and greater then signs). Well if you do it this way it calls addref without calling release correctly and you get those 4 memory leaks.

You can find more information at:

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dx81_c/directx_cpp/Intro/ProgramCPP/COM/UsingATLWithDx8.asp

After making the change to what they recommended I was fine. Hope it works for you or anyone else using Smart Pointers which I find as great for DX apps as you don't have to call Release.



In the making Tread Wars - Tank Battle game
Powered by SKEngine
http://www.highendgaming.com

[edited by - codeguy on February 16, 2004 10:47:45 PM]
In the making Tread Wars - Tank Battle gamePowered by SKEnginehttp://www.highendgaming.com
Advertisement
You need a smart pointer that lets you assign a custom deleter to call release.

check out

http://www.boost.org/libs/smart_ptr/sp_techniques.html#com


shared_ptr make_shared_from_COM(IDirect3d * p)
{
p->AddRef();
shared_ptr pw(p, mem_fn(&IDirect3d::Release));
return pw;
}


quote:Original post by codeguy
[...]

Just to clarify what codeguy said:
CComPtr<> increments the reference count of the source pointer on assignment. If you don''t want that you should Attach() instead of assigning.

This brings up another point: It''s always good to post a code snippet about your problem (people would''ve spotted the mistake, then)

Muhammad Haggag

This topic is closed to new replies.

Advertisement