sharpdx / SharpDX

SharpDX GitHub Repository
http://sharpdx.org
MIT License
1.69k stars 638 forks source link

D3D12 ResizeBuffers throws after D2D DeviceContext.BeginDraw via D3D11On12 #903

Closed Axiverse closed 7 years ago

Axiverse commented 7 years ago

It seems like BeginDraw()/EndDraw() might be saving a COM pointer somewhere. ResizeBuffer throws saying back buffer resources need to be released first. ResizeBuffers executes without errors without the BeginDraw()/EndDraw() calls.

D2D on D3D12 via: https://github.com/Microsoft/DirectX-Graphics-Samples/blob/master/Samples/Desktop/D3D1211On12/src/D3D1211On12.cpp#L152

D2D on D3D12 resize via: https://github.com/GameTechDev/FlipModelD3D12/blob/master/Source/sample_dx12.cpp#L827

xoofx commented 7 years ago

Haven't checked the details, afair, we don't do anything special for these methods in SharpDX (so we don't increment reference count). So the problem is elsewhere in your app.

Axiverse commented 7 years ago

I see. I just built and verified that there isn't anything special going on. Is there any way to force COM garbage collection? I've called ReportLiveDeviceObjects, and the only difference is that there are these objects:

D3D11 WARNING:  Live ID3D11Texture2D at 0x00000140D3FE44F0, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #425: LIVE_TEXTURE2D]
D3D11 WARNING:  Live ID3D11RenderTargetView at 0x00000140D3FCBB60, Refcount: 0, IntRef: 0 [ STATE_CREATION WARNING #428: LIVE_RENDERTARGETVIEW]
D3D11 WARNING:  Live ID3D11Texture2D at 0x00000140D3FE5BF0, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #425: LIVE_TEXTURE2D]
D3D11 WARNING:  Live ID3D11RenderTargetView at 0x00000140B8EDB000, Refcount: 0, IntRef: 0 [ STATE_CREATION WARNING #428: LIVE_RENDERTARGETVIEW]

I'm assuming that these are associated with the two swap buffers. Each RenderTargetView has 0 internal and external references, however it doesn't seems to be released. I'm assuming the 1 reference to the two textures are from the RenderTargetView

Axiverse commented 7 years ago

It seems like the objects may not be cleaned up immediately. Calling flush after all the disposes calls will clean them up on the DirectX side.

https://stackoverflow.com/questions/44155133/directx11-com-object-with-0-references-not-released