From 93c82feb983ba8f2fecc3b8197e7741c685af4b2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 16 Jul 2022 15:59:10 +0200 Subject: [PATCH] Reset default device on dispose --- src/ComputeSharp/Graphics/Helpers/DeviceHelper.Factory.cs | 6 ++++++ tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Factory.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Factory.cs index 78bfce29..cd010295 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Factory.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Factory.cs @@ -94,6 +94,12 @@ partial class DeviceHelper { lock (DevicesCache) { + // Remove the default device from the cache, if it has been disposed + if (device == defaultDevice) + { + defaultDevice = null; + } + DevicesCache.Remove(device.Luid); if (Configuration.IsDebugOutputEnabled) diff --git a/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs b/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs index 55d851f5..4622eb31 100644 --- a/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs +++ b/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs @@ -13,7 +13,7 @@ namespace ComputeSharp.Tests.DeviceLost; [TestCategory("DeviceDisposal")] public class DeviceDisposalTests { - [CombinatorialTestMethod] + [TestMethod] public unsafe void DeviceDisposal_GetDefault_ReferenceCounting() { using ComPtr d3D12Device = default;