[SlimDX][DX11] Device object not being released?

Started by
14 comments, last by Tape_Worm 12 years, 4 months ago
Ok, so I'm encountering some weirdness with SlimDX + D3D11/DXGI.

I load up my app, switch to full screen mode (I'm doing this manually in code because I think there was an issue with WinForms and DXGI not handling the ALT+ENTER properly, no idea if it's been corrected), click on on textpad (or any other application) outside of the full screen app (the extra application is on another monitor), and I do this a couple of times.

I get this when I close the app:
Total of 0 objects still alive.
D3D11: WARNING: Live Device: Name="ATI Radeon HD 4550 D3D11Device", Addr=0x000000000047EF00, ExtRef=1 [ STATE_CREATION WARNING #2097297: LIVE_DEVICE ]
D3D11: WARNING: Live Query: Name="unnamed", Addr=0x000000001E102CD0, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097280: LIVE_QUERY ]
D3D11: WARNING: Live Sampler: Name="unnamed", Addr=0x000000001E102A20, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097268: LIVE_SAMPLER ]
D3D11: WARNING: Live RasterizerState: Name="unnamed", Addr=0x000000001E102790, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097277: LIVE_RASTERIZERSTATE ]
D3D11: WARNING: Live DepthStencilState: Name="unnamed", Addr=0x000000001E102580, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097274: LIVE_DEPTHSTENCILSTATE ]
D3D11: WARNING: Live BlendState: Name="unnamed", Addr=0x000000001E1023D0, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097271: LIVE_BLENDSTATE ]
D3D11: WARNING: Live Context: Name="unnamed", Addr=0x000000001E0B0B80, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097226: LIVE_CONTEXT ]
D3D11: WARNING: Live Device Child Summary: Device Addr=0x000000000047EF00
Using ID3D11Debug::ReportLiveDeviceObjects with D3D11_RLDO_DETAIL will help drill into object lifetimes. Objects with ExtRef=0 and IntRef=0 will be eventually destroyed through typical Immediate Context usage. However, if the application requires these objects to be destroyed sooner, ClearState followed by Flush on the Immediate Context will realize their destruction.
Live Context: 1
Live Buffer: 0
Live Texture1D: 0
Live Texture2D: 0
Live Texture3D: 0
Live ShaderResourceView: 0
Live RenderTargetView: 0
Live DepthStencilView: 0
Live VertexShader: 0
Live GeometryShader: 0
Live PixelShader: 0
Live InputLayout: 0
Live Sampler: 1
Live BlendState: 1
Live DepthStencilState: 1
Live RasterizerState: 1
Live Query: 1
Live Predicate: 0
Live Counter: 0
Live CommandList: 0
Live HullShader: 0
Live DomainShader: 0
Live ClassInstance: 0
Live ClassLinkage: 0
Live ComputeShader: 0
Live UnorderedAccessView: 0
[ STATE_CREATION WARNING #2097298: LIVE_OBJECT_SUMMARY ]



I've noted that there's an external reference to my D3D device object (ExtRef=1), but I'm absolutely certain I've disposed of the device object before the app closes. The weird thing is, if I ALT+ENTER back and forth many times between my application and another, it exits cleanly. Also, SlimDX is reporting that I have no outstanding references. If I run the application and just quit, it exits cleanly, if I run it, switch to full screen, it exits cleanly. It appears to only happen when I've clicked on another application outside of the window.

I'm at a loss as to why this could be happening. Any suggestions?
Advertisement
Oh, I forgot to mention that I'm using SlimDX (March 2011) version 4.0.11.43.
Hope the following helps
I'm assuming Device.ComPointer is an address.


When you call Device.Dispose(),
1. check that Disposed is true
2. check its ComPointer and see if it matches
a. the ComPointer of the device you originally created
b. the ComPointer of the device it's warning about

Hope the following helps
I'm assuming Device.ComPointer is an address.


When you call Device.Dispose(),
1. check that Disposed is true
2. check its ComPointer and see if it matches
a. the ComPointer of the device you originally created
b. the ComPointer of the device it's warning about


I have confirmed that the pointers are the same, and that the device was not previously disposed. It is still messing up.
Some extra info:

I've tested by doing absolutely nothing, no rendering, not even clearing the screen. Just creating a device, and a swap chain. That's it, and I -still- get this popping up. I'm wondering if it's not a SlimDX issue or a driver problem (I think that'd be pretty unlikely)? I walked through my code one line at a time, and it is indeed calling the Dispose method on the device object.


Maybe Promit or Mike can chime in?
Hmm.

Try calling the following function repeatedly around your mode switching code

int GetRefCount(ComObject co)
{
Marshal.AddRef(co.ComPtr);
return Marshal.Release(co.ComPtr);
}

and see if the reported ref counts matches your expectations / agrees with the non-broken situation.

Some extra info:

I've tested by doing absolutely nothing, no rendering, not even clearing the screen. Just creating a device, and a swap chain. That's it, and I -still- get this popping up. I'm wondering if it's not a SlimDX issue or a driver problem (I think that'd be pretty unlikely)? I walked through my code one line at a time, and it is indeed calling the Dispose method on the device object.


Maybe Promit or Mike can chime in?


Actually, I lied a little here. I completely forgot that I'm also creating a render target view as well. However, I am certain that I'm disposing it as my own logging shows the object being created and disposed every time. I'm going to disable it and see what happens.

[quote name='Tape_Worm' timestamp='1318879587' post='4873593']
Some extra info:

I've tested by doing absolutely nothing, no rendering, not even clearing the screen. Just creating a device, and a swap chain. That's it, and I -still- get this popping up. I'm wondering if it's not a SlimDX issue or a driver problem (I think that'd be pretty unlikely)? I walked through my code one line at a time, and it is indeed calling the Dispose method on the device object.


Maybe Promit or Mike can chime in?


Actually, I lied a little here. I completely forgot that I'm also creating a render target view as well. However, I am certain that I'm disposing it as my own logging shows the object being created and disposed every time. I'm going to disable it and see what happens.
[/quote]

So, I commented out the code for the render target view, and it stopped messing up the reference count. However, I uncommented the code (1 line at a time, just to see which line might have been causing the issue) and even with the completely uncommented code, it still works. I am baffled. dry.gif

I'd like to know why it messed up and said that the device wasn't released (when it definitely was) or else I'm sure it'll bite me in the ass when I'm least suspecting or prepared for it.

Update:
So, I just tried my code from earlier today (which was showing the issue) and now, mysteriously, it too is exiting cleanly. huh.gif This just gets weirder and weirder.

Hmm.

Try calling the following function repeatedly around your mode switching code

int GetRefCount(ComObject co)
{
Marshal.AddRef(co.ComPtr);
return Marshal.Release(co.ComPtr);
}

and see if the reported ref counts matches your expectations / agrees with the non-broken situation.


So I tried out your code to check the refcount. When I create the D3DDevice, it's got a count of 1 (naturally), and just before I destroy the device, it's got a count of 2, which is kind of odd. I only have a call to CreateSwapChain and the code to create the D3DDevice, so something's amiss. It claims the extra reference is an external reference, but I really have absolutely nothing else in here that's adding to the ref count. It just makes no sense.

Thanks for your help.

[quote name='jameszhao00' timestamp='1318880299' post='4873597']
Hmm.

Try calling the following function repeatedly around your mode switching code

int GetRefCount(ComObject co)
{
Marshal.AddRef(co.ComPtr);
return Marshal.Release(co.ComPtr);
}

and see if the reported ref counts matches your expectations / agrees with the non-broken situation.


So I tried out your code to check the refcount. When I create the D3DDevice, it's got a count of 1 (naturally), and just before I destroy the device, it's got a count of 2, which is kind of odd. I only have a call to CreateSwapChain and the code to create the D3DDevice, so something's amiss. It claims the extra reference is an external reference, but I really have absolutely nothing else in here that's adding to the ref count. It just makes no sense.

Thanks for your help.
[/quote]

Locating where it broke:

Go into PIX. Select "A replayable Direct3D call stream". Run your app. Break your app. Then in PIX, find (binary search :P) the exact call site where "D3D11 Device" (in the Objects window) has unexpected "App Refs".

Note: To actually view the app refs, for some reason you have to a) select a random frame b) select render. Make sure you're in the Mesh or Render tab when selecting different calls (to force refresh)

This topic is closed to new replies.

Advertisement