Jump to content

  • Log In with Google      Sign In   
  • Create Account


check if released


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 JezzaP   Members   -  Reputation: 113

Like
0Likes
Like

Posted 21 July 2009 - 08:06 AM

Is there a way in DirectX to check if a resource has already been released? If you try to release something twice, it will give Access Violations. Say I have a texture, which two pointers point to. I can release from one and nullify the pointer, but without checking if that is nullified I shan't know whether to attempt to release the other. If I wanted the pointers to be independent then I have a problem.

Sponsor:

#2 Josh Petrie   Moderators   -  Reputation: 3110

Like
0Likes
Like

Posted 21 July 2009 - 08:23 AM

You can't do this in a general and reliable fashion. However you can absolve yourself of much of the need by using CComPtr from ATL or boost::shared_ptr with a custom deleter. Then you will not need to worry about manually working with the reference counts.

Quote:

If you try to release something twice, it will give Access Violations.

If you're lucky. If your Release isn't the one that reduces the reference count to zero, nothing will go wrong until later, which is a serious issue.

Quote:

Say I have a texture, which two pointers point to.

Then either both sites that hold the texture interface pointer should have claimed reference counts on that interface (via AddRef or the original interface that gave you the texture) and thus should both Release the reference count, or one site must be considered the "owner" and has the responsibility for calling Release when necessary; the longer-lived site must be the owner for the pointer to remain valid.

Using CComPtr or something like it allows you to automate these responsibilities via RAII.

Josh Petrie | Core Tools Engineer, 343i | Microsoft C++ MVP


#3 JezzaP   Members   -  Reputation: 113

Like
0Likes
Like

Posted 21 July 2009 - 08:14 PM

Thanks, I never of the existence of such classes. That's a real help.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS