From bce80f17f3ae8e234f62821f47575ce203fda903 Mon Sep 17 00:00:00 2001 From: Katter Date: Mon, 14 Oct 2024 01:00:10 +0500 Subject: [PATCH] DX11ScreenCapture proper dispose previous capture resources --- SightKeeper.Application.Windows/DX11ScreenCapture.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/SightKeeper.Application.Windows/DX11ScreenCapture.cs b/SightKeeper.Application.Windows/DX11ScreenCapture.cs index 2505c120..e595a9fb 100644 --- a/SightKeeper.Application.Windows/DX11ScreenCapture.cs +++ b/SightKeeper.Application.Windows/DX11ScreenCapture.cs @@ -54,9 +54,12 @@ public DX11ScreenCapture() private unsafe ReadOnlySpan2D Capture() { - _device.ImmediateContext.UnmapSubresource(_screenTexture, 0); - _screenResource?.Dispose(); - _outputDuplication.ReleaseFrame(); + if (_screenResource != null) + { + _device.ImmediateContext.UnmapSubresource(_screenTexture, 0); + _screenResource.Dispose(); + _outputDuplication.ReleaseFrame(); + } _outputDuplication.TryAcquireNextFrame(1000, out _, out _screenResource).CheckError(); using (var screenTexture2D = _screenResource.QueryInterface()) _device.ImmediateContext.CopyResource(screenTexture2D, _screenTexture);