Sign in to follow this  

Map::Insert a COM Object question, about storing and releasing[Solved]

This topic is 1793 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

Hi,

This may seems as a weird question but, is this the correct way to "Store" a ID3D11ShaderResourceView* Pointer?

Am trying to store COM Object pointer inside a simple map with a std::string key.

I get no error's but when I quit the program it complains about unreleased objects.

Neither do I get a error when I try to release the "objects".

So I start to question my method about how to release it.

The reason why I am using a while loop with .empty(); is cause I can't seems to use the [] operator except for [0]. while am at it would appreciate if someone could explain that to >.<

 

		
ID3D11ShaderResourceView* t;
std::map<std::string,ID3D11ShaderResourceView*> TotalTexture;
std::vector<std::string> TotalTextureToLoad;
TotalTexture.insert
(
TotalTexture.end(),std::pair<std::string,ID3D11ShaderResourceView*>(TotalTextureToLoad[i],t)

);
while(!TotalTexture.empty())
{
	TotalTexture.begin()->second->Release();
	TotalTexture.erase(TotalTexture.begin());
}

 

 

 

 

 

    

Share this post


Link to post
Share on other sites

Have you checked the return of the method call, I have never used D3D, but in the reference manual it says it will print the reference count, so you can check if the problem is here or otherwhere.

 

To clean the map, I believe the code should be something like this:

 

for (std::map<std::string,ID3D11ShaderResourceView*>::iterator it = TotalTexture.begin(); it != TotalTexture.end(); ++it){
	it->second->Release();
}
TotalTexture.clear();

 

References I used are those two:

http://www.cplusplus.com/reference/map/map/begin/

http://www.cplusplus.com/reference/map/map/clear/

Share this post


Link to post
Share on other sites

Got it to work, The problem was that I Called the loadAll(), twice. and I was trying to insert the same key inside the map, so there were a certain numbers of objects that wasnt getting released, cause the pointer was not inside the map.

Share this post


Link to post
Share on other sites

This topic is 1793 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.

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