Jump to content
  • Advertisement
Sign in to follow this  
nietakt

[SlimDX] - D3D9 - DepthStencilSurface disposal

This topic is 2823 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 there!

As the subject says, I'm having a problem with DepthStencilSurface in SlimDX & D3D9.

The thing is that according to my general experience/observation and this article
all the DX objects NOT created by the application explicitly don't need to be released (= no need to call Dispose() on them).

And this works e.g. for the backbuffer:

Surface bbuf = dev.GetBackBuffer(0, 0);
//doing something super-duper with bbuf...
//then doing many other things (device is still using the same BackBuffer)
//quitting the application
//=> no leak (Total of 0 objects still alive.)

However, when I get the DepthStencil surface, it keeps leaking:

Surface ds = dev.DepthStencilSurface;
//doing something unimaginable with ds...
//then doing some cool stuff again (device is still using the same DepthStencil)
//quitting the app
//=> Object of type SlimDX.Direct3D9.Surface was not disposed.

Then again, if I do call Dispose(), like this:

Surface ds = dev.DepthStencilSurface;
//doing something mind-blowing with ds...
ds.Dispose();
//then doing some cool stuff once again (device is still using the same DepthStencil)
//quitting the app
//=> no leak



I find it pretty counterintuitive - is there any reason for this?
Thanks :).

P.S. SlimDX guys - this question is in no way trying to belittle your efforts, SlimDX is very useful and handy - thank you for your work :).

[Edited by - nietakt on October 23, 2010 4:29:56 AM]

Share this post


Link to post
Share on other sites
Advertisement
You should read part 2 of that article, because this is one of the edge case pitfalls mentioned in the closing paragraph of part 1.

This is an unfortunate consequence of trying to use IDisposable for SlimDX COM objects -- a mistake we will not be repeating in version 2, which will have explicit AddReference() and Release() calls.

The issue is that your depth stencil surface is implicitly created by D3D9, but SlimDX doesn't know about it. The first time it sees it is when you call get_DepthStencilSurface -- SlimDX will see that there is no entry in its RCW object table for that particular COM object and add one, calling AddRef() on the IUnknown. This means you'd need to Dispose() that object to have SlimDX call Release().

It's really obnoxious, but we basically designed ourselves into a corner with this one. "Fixing" get_DepthStencilSurface so it works like GetBackBuffer() would be dangerous at this stage of the game, since it would break everybody else's code and also violate the IDisposable contract in a different fashion.

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!