From 7dca92dc3399bb265cf5046f1c00210d92a9dc92 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 3 Aug 2022 23:01:50 +0200 Subject: [PATCH] Stop the render loop before requesting disposal --- src/ComputeSharp.UI/Controls/AnimatedComputeShaderPanel.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ComputeSharp.UI/Controls/AnimatedComputeShaderPanel.cs b/src/ComputeSharp.UI/Controls/AnimatedComputeShaderPanel.cs index 9c3710ae..e940962a 100644 --- a/src/ComputeSharp.UI/Controls/AnimatedComputeShaderPanel.cs +++ b/src/ComputeSharp.UI/Controls/AnimatedComputeShaderPanel.cs @@ -90,6 +90,12 @@ public sealed partial class AnimatedComputeShaderPanel : SwapChainPanel, IDispos /// public void Dispose() { + // Also request the render loop to stop before disposing. This ensures that in case there's + // a render thread already ongoing that is using a custom frame request queue, it might have + // the ability to stop rendering immediately and safely, instead of causing the panel to remain + // alive and then just throwing an exception the next time a frame is requested in case the + // device ot other resources have also been disposed. + this.swapChainManager.StopRenderLoop(); this.swapChainManager.Dispose(); } }