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

Started by
14 comments, last by Tape_Worm 12 years, 5 months ago

[quote name='Tape_Worm' timestamp='1318900097' post='4873706']
[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)
[/quote]

Thanks for that. I've always had a hell of a time getting PIX to behave itself with .NET apps, and it was a little better tonight.

So, here's what my logging (and your ref counter code) told me before it destroyed the ID3D11Device:
[10/17/2011 08:24:04 PM] D3D Device Ref Count #: 3

So, according to that, there were 3 references to the device.

Then I poured through the calls in PIX, and I found a very different story. The AppRefs never went above 2, and always fell back to 1 (until the final Dispose call on the device object, which then said there were no more references). But, when I turn on the return result I can see in each AddRef/Release from the reference counting code that the values are higher. In some cases, it returns as high as 5. I understand these could be internal references, and as such, and my releasing of my only reference to the ID3D11Device is only going to decrement the count by 1, leaving those other references.
Advertisement
A little update:
I've upgraded to SlimDX Sep 2011. The problem remains though.

Urge to kill is rising...
So, I stripped everything down to a very minimal application and switching between applications still gives me an unreleased device object.

The funny thing is, if I ALT+TAB back and forth this does not happen when I close. If I click on an external application and go back to my application (multiple times) it gives me the warning about the unreleased device object when I close.

Again, here's the warning for anyone who might have an inkling as to what's going on here:


Total of 0 objects still alive.
D3D11: WARNING: Live Device: Name="unnamed", Addr=0x00000000005DDEE0, ExtRef=1 [ STATE_CREATION WARNING #2097297: LIVE_DEVICE ]
D3D11: WARNING: Live Texture2D: Name="unnamed", Addr=0x000000001DAF4EC0, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097235: LIVE_TEXTURE2D ]
D3D11: WARNING: Live RenderTargetView: Name="unnamed", Addr=0x000000001DAF9B00, ExtRef=0, IntRef=0 [ STATE_CREATION WARNING #2097244: LIVE_RENDERTARGETVIEW ]
D3D11: WARNING: Live Texture2D: Name="unnamed", Addr=0x000000001DAF43B0, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097235: LIVE_TEXTURE2D ]
D3D11: WARNING: Live Query: Name="unnamed", Addr=0x000000001DAF2190, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097280: LIVE_QUERY ]
D3D11: WARNING: Live Sampler: Name="unnamed", Addr=0x000000001DAF1E00, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097268: LIVE_SAMPLER ]
D3D11: WARNING: Live RasterizerState: Name="unnamed", Addr=0x000000001DAF1A80, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097277: LIVE_RASTERIZERSTATE ]
D3D11: WARNING: Live DepthStencilState: Name="unnamed", Addr=0x000000001DAF1730, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097274: LIVE_DEPTHSTENCILSTATE ]
D3D11: WARNING: Live BlendState: Name="unnamed", Addr=0x000000001DAF11A0, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097271: LIVE_BLENDSTATE ]
D3D11: WARNING: Live Context: Name="unnamed", Addr=0x000000001DAA00B0, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097226: LIVE_CONTEXT ]
D3D11: WARNING: Live Device Child Summary: Device Addr=0x00000000005DDEE0
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: 2
Live Texture3D: 0
Live ShaderResourceView: 0
Live RenderTargetView: 1
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'm about to give up and accept it as part of life, I really hope leaving this this doesn't cause any major issues in the future.
I'm not using slimdx but I have the same issue (exact same error message) and I did a pix capture of it.
It happens when you close a full screen application. It doesn't show any warning when in window mode.
.
Did anyone find a solution for this?


// Initialization
4 D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 2, NULL, 0, 7, 0x0041FD88, 0x0041FDC4 --> 0x05566820, 0x0041FDC8 --> 0x05566070, NULL, 0x0041FDCC --> 0x055D9C78) 1262568822
5 CreateObject(D3D11 Device, 0x05566070) 1651416894
6 CreateObject(DXGI Factory, 0x05566718) 1651427760
7 CreateObject(DXGI Adapter, 0x05566768) 1651429571
8 CreateObject(DXGI Device, 0x055667C0) 1651431081
9 CreateObject(DXGI Swap Chain, 0x05566820) 1651432590
10 CreateObject(DXGI Surface, 0x055668B8) 1651434703
11 CreateObject(D3D11 Texture2D, 0x05566918) 1651437721
12 CreateObject(D3D11 Device Context, 0x055D9C78) 1651451305
13 <0x05566820> IDXGISwapChain::GetBuffer(0, IID_ID3D11Texture2D, 0x0041F67C --> 0x05566918) 1651467907
14 <0x05566070> ID3D11Device::CreateRenderTargetView(0x05566918, NULL, 0x0041F654 --> 0x05566DB8) 1651472133
15 CreateObject(D3D11 Render Target View, 0x05566DB8) 1651537031
16 <0x05566918> ID3D11Texture2D::AddRef() 1651547596
17 <0x05566DB8> ID3D11RenderTargetView::AddRef() 1651549407
18 <0x05566918> ID3D11Texture2D::Release() 1651550614
19 <0x05566DB8> ID3D11RenderTargetView::Release() 1651551520
20 <0x05566DB8> ID3D11RenderTargetView::AddRef() 1651557557

// Update frames ...
21 <0x05566820> IDXGISwapChain::GetFullscreenState(0x0041F778, NULL) 1683438579
22 <0x055D9C78> ID3D11DeviceContext::OMSetRenderTargets(1, 0x05737AA8 --> { 0x05566DB8 }, NULL) 1683450351
23 <0x055D9C78> ID3D11DeviceContext::RSSetViewports(1, 0x0041F52C) 1683475405
24 <0x05566820> IDXGISwapChain::Present(0, 0) 1728516577

...
// Uninitialization
81 <0x05566918> ID3D11Texture2D::Release() 1844018799
82 <0x05566DB8> ID3D11RenderTargetView::Release() 1844024534
83 <0x05566DB8> ID3D11RenderTargetView::Release() 1844029062
84 <0x055D9C78> ID3D11DeviceContext::OMSetRenderTargets(0, NULL, NULL) 1844036306
85 DestroyObject(D3D11 Render Target View, 0x05566DB8) 1844043853
86 <0x055D9C78> ID3D11DeviceContext::Release() 1844049286
87 <0x05566820> IDXGISwapChain::Release() 1844051701
88 DestroyObject(DXGI Swap Chain, 0x05566820) 1844260884
89 DestroyObject(DXGI Surface, 0x055668B8) 1844267223
90 DestroyObject(D3D11 Texture2D, 0x05566918) 1844269940
91 <0x05566070> ID3D11Device::Release() 1844274468
92 DestroyObject(D3D11 Device, 0x05566070) 1844276581
93 DestroyObject(D3D11 Device Context, 0x055D9C78) 1844278694
94 DestroyObject(DXGI Device, 0x055667C0) 1844280807
95 DestroyObject(DXGI Adapter, 0x05566768) 1844282919


Seems like the DXGI Factory is not destroyed... I use CreateDeviceAndSwapChain, I do not manage the Factory.
I tried calling "ClearState" and "Flush" just before I release the context but "Flush" crash my application (again only in fullscreen).
I fixed my problem by calling "SetFullscreenState(false, NULL);" just before releasing the swap chain. Not sure if its what I should have done in the first place but it kinda makes sense.

I fixed my problem by calling "SetFullscreenState(false, NULL);" just before releasing the swap chain. Not sure if its what I should have done in the first place but it kinda makes sense.


Yep, Microsoft recommends you do that before destroying a swap chain:
[font="Arial"][color=#2A2A2A]
[color=#2A2A2A]If the swap chain is in full-screen mode, before you release it you must use SetFullscreenState[color=#2A2A2A] to switch it to windowed mode. For more information about releasing a swap chain, see the "Destroying a Swap Chain" section of DXGI Overview[color=#2A2A2A].[/quote][color=#2A2A2A][/font]
[font="Arial"]
[/font]
[font="Arial"]However, that didn't help with my issue. I just said to hell with it and moved on.[/font]

This topic is closed to new replies.

Advertisement