[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.

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 on other sites
No ideas? Or maybe my mumble was unclear?

Share on other sites
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 on other sites
Okay, now I get it :). Thank you for the sound explanation, jpetrie.

See you next time!

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 11
• 11
• 9
• Forum Statistics

• Total Topics
631773
• Total Posts
3002270
×