vector of LPDIRECT3DTEXTURE9

Started by
7 comments, last by Promit 14 years, 10 months ago
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
Advertisement
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.
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
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.
OK, Thank You
Alternately, use a vector of smart pointers like ATL's CComPtr and let that worry about calling AddRef() and Release().
is that alternatively or preferably?
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]

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]
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

This topic is closed to new replies.

Advertisement