Sign in to follow this  
A_B

vector of LPDIRECT3DTEXTURE9

Recommended Posts

A_B    122
Hi, I have a question about the functioning of vectors and how this relates to directX's LPDIRECT3DTEXTURE9. I made a vector containing LPDIRECT3DTEXTURE9. I fill the vector by first loading such texture in a 'buffer' and then using push_back. Is is necessary to release the 'buffer' (I hope it is not because if it is it messes up my app :p) Thanks A_B

Share this post


Link to post
Share on other sites
Evil Steve    2017
Yes, it is. You must call Release() on all interfaces that you create or AddRef() manually. So at cleanup time, you'll want to loop over each texture in the vector and call Release() on it.

Share this post


Link to post
Share on other sites
A_B    122
yesyes I do that but I mean do I have to release the buffertexture itself I 'push_backed' to the vector:

buffer->Release();

and later:

vector[pos]->Release();


Thanks
A_B

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by A_B
yesyes I do that but I mean do I have to release the buffertexture itself I 'push_backed' to the vector:

buffer->Release();

and later:

vector[pos]->Release();


Thanks
A_B
You need to have one Release() for every creation of the texture. You don't need to if you just push_back'd onto a vector, a LPDIRECT3DTEXTURE9 is just a pointer, adding it to a vector will not increase its reference count.
You can treat it pretty much like any class allocated with new - you need to delete it exactly once, once you're finished using it.

Share this post


Link to post
Share on other sites
SiCrane    11839
Alternately, use a vector of smart pointers like ATL's CComPtr and let that worry about calling AddRef() and Release().

Share this post


Link to post
Share on other sites
Promit    13246
Quote:
Original post by MJP
Quote:
Original post by A_B
is that alternatively or preferably?


Perferably, in my opinion. It's quite liberating to free yourself from all of the AddRef and Release nonsense. [smile]
Yeah, SlimDX is pretty awesome. [grin]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this