From de3ba7bb207fc7f125f3ea76bd868941885f579e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 19 Aug 2022 14:23:13 +0200 Subject: [PATCH] Release previous manager when setting a new one --- .../Interop/Effects/PixelShaderEffect.Properties.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.Properties.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.Properties.cs index 856bb492..4c4df49c 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.Properties.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.Properties.cs @@ -248,8 +248,16 @@ unsafe partial struct PixelShaderEffect } } + ref ID2D1ResourceTextureManager* currentResourceTextureManager = ref this.resourceTextureManagerBuffer[resourceTextureIndex]; + + // If there's already an existing manager at this index, release it + if (currentResourceTextureManager is not null) + { + ((IUnknown*)currentResourceTextureManager)->Release(); + } + // Store the resource texture manager into the buffer - this.resourceTextureManagerBuffer[resourceTextureIndex] = resourceTextureManager.Detach(); + currentResourceTextureManager = resourceTextureManager.Detach(); return S.S_OK; }