Jump to content
  • Advertisement
Sign in to follow this  
spektrum

Pointer to a Direct3D object?

This topic is 3654 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm not incredibly familiar with COM and I'm wondering if it is a bad idea to have a multiple pointers to a COM object. The reason I'm concerned is because I'm not quite sure how the whole AddRef() thing works and I don't want a reference counter getting out of hand. So, say for example, I create a d3d effect: ID3D10Effect * effect; D3DX10CreateEffectFromFile( filename, NULL, NULL, "fx_4_0", dwShaderFlags, 0, pDevice, NULL, NULL, &effect, NULL, NULL ); Would it be ok to do this? ID3D10Effect * pointerToEffect = effect; or create a function pointer? ID3D10Effect * Function() { return effect; } I tried to do some research on this but came up with little. I'm hoping I wouldn't have to call Release() every time I created a pointer.

Share this post


Link to post
Share on other sites
Advertisement
You could use CComPtr<T>, which manages the AddRef and Release calls for you.

All you basically need to do is understand that when you intend to store a reference (pointer) to the COM interface, you should generally call AddRef(). And thus when you are done, call Release(). There are a handful of API calls that will implicitly AddRef() the interface or otherwise alter the reference count (such as the functions that create the interface), so you need to call Release() then, too.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!