From d304a0ff96000832b3d03d0012075db2a8d48e8f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 10 Jan 2023 17:43:33 +0100 Subject: [PATCH] Fix exception when getting constant buffer for empty type --- .../Extensions/ID2D1EffectExtensions.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ComputeSharp.D2D1.Uwp/Extensions/ID2D1EffectExtensions.cs b/src/ComputeSharp.D2D1.Uwp/Extensions/ID2D1EffectExtensions.cs index 88822c3c..3c25d334 100644 --- a/src/ComputeSharp.D2D1.Uwp/Extensions/ID2D1EffectExtensions.cs +++ b/src/ComputeSharp.D2D1.Uwp/Extensions/ID2D1EffectExtensions.cs @@ -29,6 +29,15 @@ internal static unsafe class ID2D1EffectExtensions where T : unmanaged, ID2D1PixelShader { int constantBufferSize = D2D1PixelShader.GetConstantBufferSize(); + + // Special cases the constant buffer type being empty. If that's the case, there is no + // need to try to retrieve the constant buffer from the underlying effect anyway, and + // most importantly, the ID2D1EffectImpl from ComputeSharp.D2D1 will return E_INVALIDARG. + if (constantBufferSize == 0) + { + return default; + } + byte[] buffer = ArrayPool.Shared.Rent(constantBufferSize); fixed (byte* p = buffer)