From 2022a73754f7caf2d6b91992d96a3f078677d86c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 7 Oct 2023 19:57:48 +0200 Subject: [PATCH] Improve PixelShaderEffect.Factory method --- .../Interop/Effects/PixelShaderEffect.cs | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs index fb3a2acf..38e87929 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs @@ -150,8 +150,22 @@ internal unsafe partial struct PixelShaderEffect { @this = (PixelShaderEffect*)NativeMemory.Alloc((nuint)sizeof(PixelShaderEffect)); globalsHandle = GCHandle.Alloc(globals); + + @this->lpVtblForID2D1EffectImpl = VtblForID2D1EffectImpl; + @this->lpVtblForID2D1DrawTransform = VtblForID2D1DrawTransform; + @this->referenceCount = 1; + @this->globalsHandle = globalsHandle; + @this->constantBuffer = null; + @this->d2D1TransformMapper = null; + @this->d2D1DrawInfo = null; + @this->d2D1EffectContext = null; + @this->resourceTextureManagerBuffer = default; + + *effectImpl = (IUnknown*)@this; + + return S.S_OK; } - catch (Exception) + catch (Exception e) { // Free the effect, if we have one NativeMemory.Free(@this); @@ -164,24 +178,8 @@ internal unsafe partial struct PixelShaderEffect *effectImpl = null; - return E.E_OUTOFMEMORY; + return Marshal.GetHRForException(e); } - - *@this = default; - - @this->lpVtblForID2D1EffectImpl = VtblForID2D1EffectImpl; - @this->lpVtblForID2D1DrawTransform = VtblForID2D1DrawTransform; - @this->referenceCount = 1; - @this->globalsHandle = globalsHandle; - @this->constantBuffer = null; - @this->d2D1TransformMapper = null; - @this->d2D1DrawInfo = null; - @this->d2D1EffectContext = null; - @this->resourceTextureManagerBuffer = default; - - *effectImpl = (IUnknown*)@this; - - return S.S_OK; } ///