From 6de0ca24bf843b55f50be081c1810e7a3c7534c9 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 15 Aug 2022 13:43:50 +0200 Subject: [PATCH] Fix loading of resource textures when rendering effect --- ...ixelShaderEffect.ID2D1EffectImplMethods.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs index 6c533fce..130eb816 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs @@ -172,10 +172,26 @@ internal unsafe partial struct PixelShaderEffect foreach (ref readonly D2D1ResourceTextureDescription resourceTextureDescription in new ReadOnlySpan(@this->resourceTextureDescriptions, @this->resourceTextureDescriptionCount)) { using ComPtr resourceTextureManager = @this->resourceTextureManagerBuffer[resourceTextureDescription.Index]; + + // If the current resource texture manager is not set, we cannot render, as there's an unbound resource texture + if (resourceTextureManager.Get() is null) + { + hresult = E.E_NOT_VALID_STATE; + + break; + } + using ComPtr resourceTextureManagerInternal = default; - // Get the ID2D1ResourceTextureManagerInternal object (as above, this is guaranteed to succeed here) - _ = resourceTextureManager.CopyTo(resourceTextureManagerInternal.GetAddressOf()); + // Get the ID2D1ResourceTextureManagerInternal object + hresult = resourceTextureManager.CopyTo(resourceTextureManagerInternal.GetAddressOf()); + + // This cast should always succeed, as when an input resource texture managers is set it's + // also checked for ID2D1ResourceTextureManagerInternal, but still validate for good measure. + if (!Windows.SUCCEEDED(hresult)) + { + break; + } using ComPtr d2D1ResourceTexture = default;