@@ -162,12 +162,12 @@ private unsafe bool ChildWindowToXaml(nint parent, UIElement presenter)
162162 ] ;
163163
164164 Windows . Win32 . Foundation . HRESULT hr = default ;
165- ComPtr < ID3D11Device > pD3D11Device = default ;
166- ComPtr < ID3D11DeviceContext > pD3D11DeviceContext = default ;
167- ComPtr < IDXGIDevice > pDXGIDevice = default ;
168- ComPtr < IDCompositionDevice > pDCompositionDevice = default ;
169- ComPtr < IDCompositionVisual > pChildVisual = default ;
170- ComPtr < IUnknown > pControlSurface = default ;
165+ using ComPtr < ID3D11Device > pD3D11Device = default ;
166+ using ComPtr < ID3D11DeviceContext > pD3D11DeviceContext = default ;
167+ using ComPtr < IDXGIDevice > pDXGIDevice = default ;
168+ using ComPtr < IDCompositionDevice > pDCompositionDevice = default ;
169+ using ComPtr < IUnknown > pControlSurface = default ;
170+ ComPtr < IDCompositionVisual > pChildVisual = default ; // Don't dispose this one, it's used by the compositor
171171
172172 // Create the D3D11 device
173173 foreach ( var driverType in driverTypes )
@@ -209,21 +209,15 @@ private unsafe bool ChildWindowToXaml(nint parent, UIElement presenter)
209209 outputLink = ContentExternalOutputLink . Create ( compositor ) ;
210210
211211 var target = outputLink . As < IDCompositionTarget > ( ) ;
212-
213212 target . SetRoot ( ( nint ) pChildVisual . Get ( ) ) ;
213+
214214 outputLink . PlacementVisual . Size = new ( 0 , 0 ) ;
215215 outputLink . PlacementVisual . Scale = new ( 1 / ( float ) presenter . XamlRoot . RasterizationScale ) ;
216216 ElementCompositionPreview . SetElementChildVisual ( presenter , outputLink . PlacementVisual ) ;
217217
218218 // Commit the all pending DComp commands
219219 pDCompositionDevice . Get ( ) ->Commit ( ) ;
220220
221- pControlSurface . Release ( ) ;
222- pDCompositionDevice . Release ( ) ;
223- pDXGIDevice . Release ( ) ;
224- pD3D11Device . Release ( ) ;
225- pD3D11DeviceContext . Release ( ) ;
226-
227221 var dwAttrib = Convert . ToUInt32 ( true ) ;
228222
229223 return
0 commit comments