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;