Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


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: 3887

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 | Game Developer, Undead Labs


#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