Jump to content
  • Advertisement
Sign in to follow this  
schupf

Is it save to release resources?

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

Hello, I have a little question about Direct3D10. Is it save to release a resource that has been used to create another resource onto it (for example a view). Example:
 ID3D10Texture2D* dsTex = NULL;
// ...
device->CreateTexture2D(&dsDesc, NULL, &dsTex); // create 2D texture

device->CreateDepthStencilView(dsTex, &dsvDesc, &dsv); // create view onto 2D texture

dsTex->Release(); // Release texture
I create a 2D texture. After the call of CreateTexture2D() the ref count of dsTex is 1. Then I create a DSV with CreateDepthStencilView(). After the call of CreateDepthStencilView() dsv has ref count 1 and dsTex has (surprisingly) still a ref count of 1. Then I release the texture and the texture is destroyed. I use this code and it works, but I want to know if this is just coincidence or if this is always save? I would understand why this code works if the ref count of the 2D texture was 2 after the call of CreateDepthStencilView() (because the DSV references the texture), but its 1. So actually I delete the texture which is referenced by the DSV. Why does this work?

Share this post


Link to post
Share on other sites
Advertisement
First at all. The COM-standard defines that the return values form AddRef and Release are only for diagnostic purpose. They don’t need to represent the real ref count of an object.

Direct3D 10 (and 11) uses two references counters. An internal and an external one. The reason for this could be to prevent an API user to release an object that is still used by another object. I see such things in DX9 code that tends to behave very strange after this.

Therefore it is safe in this case. It’s defined as not safe to release a resource that is assigned to the device as an assignment to the current device pipeline would not change the reference count of an object.

Share this post


Link to post
Share on other sites
Thanks Demirug.

@XVincentX: I wish it was so, but the reality is different. The documention is really inconsistent about telling you when the ref counter is manipulated.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!