Repository: files-community/Files
File: src/Files.App/ViewModels/UserControls/Previews/ShellPreviewViewModel.cs (C#)

Code before:
						0, 0, 0, 0,
						new(parent),
						HMENU.Null,
						hInst);
				}
			}

			_ = ChildWindowToXaml(parent, presenter);
		}

		private unsafe bool ChildWindowToXaml(nint parent, UIElement presenter)
		{
			D3D_DRIVER_TYPE[] driverTypes =
			[
				D3D_DRIVER_TYPE.D3D_DRIVER_TYPE_HARDWARE,
				D3D_DRIVER_TYPE.D3D_DRIVER_TYPE_WARP,
			];

			HRESULT hr = default;
			Guid IID_IDCompositionDevice = typeof(IDCompositionDevice).GUID;
			using ComPtr<ID3D11Device> pD3D11Device = default;
			using ComPtr<ID3D11DeviceContext> pD3D11DeviceContext = default;
			using ComPtr<IDXGIDevice> pDXGIDevice = default;
			using ComPtr<IDCompositionDevice> pDCompositionDevice = default;
			using ComPtr<IUnknown> pControlSurface = default;
			ComPtr<IDCompositionVisual> pChildVisual = default; // This should not be disposed this; otherwise, it will crash

			// Create the D3D11 device
			foreach (var driverType in driverTypes)
			{
				hr = PInvoke.D3D11CreateDevice(
					null, driverType, new(nint.Zero),
					D3D11_CREATE_DEVICE_FLAG.D3D11_CREATE_DEVICE_BGRA_SUPPORT,
					null, /* FeatureLevels */ 0, /* SDKVersion */ 7,
					pD3D11Device.GetAddressOf(), null,
					pD3D11DeviceContext.GetAddressOf());

				if (hr.Succeeded)
					break;
			}

			if (pD3D11Device.IsNull)
				return false;

			// Create the DComp device
			pDXGIDevice.Attach((IDXGIDevice*)pD3D11Device.Get());
			hr = PInvoke.DCompositionCreateDevice(
				pDXGIDevice.Get(),
				&IID_IDCompositionDevice,
				(void**)pDCompositionDevice.GetAddressOf());
			if (hr.Failed)

Review comment (bug):
```suggestion
			ComPtr<IDCompositionVisual> pChildVisual = default; // This shouldn't be disposed as it can cause a crash
```

Code after:
						0, 0, 0, 0,
						new(parent),
						HMENU.Null,
						hInst);
				}
			}

			_ = ChildWindowToXaml(parent, presenter);
		}

		private unsafe bool ChildWindowToXaml(nint parent, UIElement presenter)
		{
			D3D_DRIVER_TYPE[] driverTypes =
			[
				D3D_DRIVER_TYPE.D3D_DRIVER_TYPE_HARDWARE,
				D3D_DRIVER_TYPE.D3D_DRIVER_TYPE_WARP,
			];

			HRESULT hr = default;
			Guid IID_IDCompositionDevice = typeof(IDCompositionDevice).GUID;
			using ComPtr<ID3D11Device> pD3D11Device = default;
			using ComPtr<ID3D11DeviceContext> pD3D11DeviceContext = default;
			using ComPtr<IDXGIDevice> pDXGIDevice = default;
			using ComPtr<IDCompositionDevice> pDCompositionDevice = default;
			using ComPtr<IUnknown> pControlSurface = default;
			ComPtr<IDCompositionVisual> pChildVisual = default; // Don't dispose this one, it's used by the compositor

			// Create the D3D11 device
			foreach (var driverType in driverTypes)
			{
				hr = PInvoke.D3D11CreateDevice(
					null, driverType, new(nint.Zero),
					D3D11_CREATE_DEVICE_FLAG.D3D11_CREATE_DEVICE_BGRA_SUPPORT,
					null, /* FeatureLevels */ 0, /* SDKVersion */ 7,
					pD3D11Device.GetAddressOf(), null,
					pD3D11DeviceContext.GetAddressOf());

				if (hr.Succeeded)
					break;
			}

			if (pD3D11Device.IsNull)
				return false;

			// Create the DComp device
			pDXGIDevice.Attach((IDXGIDevice*)pD3D11Device.Get());
			hr = PInvoke.DCompositionCreateDevice(
				pDXGIDevice.Get(),
				&IID_IDCompositionDevice,
				(void**)pDCompositionDevice.GetAddressOf());
			if (hr.Failed)