Sign in to follow this  
JezzaP

check if released

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

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