Add validation for constant buffer initialization and unit test
このコミットが含まれているのは:
1 親
b866572173
コミット
ec057ce7e4
3ファイル変更
+44
-2
検索条件に一致するファイルはありません
-1
@@ -200,7 +200,6 @@ partial struct PixelShaderEffect
|
||||
opaqueInputs[i] = inputOpaqueSubRects[i].ToRectangle();
|
||||
}
|
||||
|
||||
// TODO: shouldn't there be a check for the buffer being null?
|
||||
ReadOnlySpan<byte> buffer = new(@this->constantBuffer, @this->constantBufferSize);
|
||||
|
||||
Rectangle output;
|
||||
|
||||
+7
@@ -159,6 +159,13 @@ internal unsafe partial struct PixelShaderEffect
|
||||
{
|
||||
int hresult = S.S_OK;
|
||||
|
||||
// Validate the constant buffer
|
||||
if (@this->constantBufferSize > 0 &&
|
||||
@this->constantBuffer is null)
|
||||
{
|
||||
return E.E_NOT_VALID_STATE;
|
||||
}
|
||||
|
||||
// First, set the constant buffer, if available
|
||||
if (@this->constantBuffer is not null)
|
||||
{
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Tests.Effects;
|
||||
using ComputeSharp.D2D1.Tests.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Tests;
|
||||
|
||||
[TestClass]
|
||||
[TestCategory("D2D1PixelShaderEffect")]
|
||||
public class D2D1PixelShaderEffectTests
|
||||
public partial class D2D1PixelShaderEffectTests
|
||||
{
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
|
||||
@@ -85,4 +89,36 @@ public class D2D1PixelShaderEffectTests
|
||||
{
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect((void*)1, (D2D1ResourceTextureManager)null!, 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(Win32Exception))]
|
||||
public unsafe void NullConstantBuffer_DrawImageFails()
|
||||
{
|
||||
using ComPtr<ID2D1Factory2> d2D1Factory2 = D2D1Helper.CreateD2D1Factory2();
|
||||
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
|
||||
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
|
||||
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<NullConstantBufferShader>(d2D1Factory2.Get(), null, out _);
|
||||
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<NullConstantBufferShader>(d2D1DeviceContext.Get(), (void**)d2D1Effect.GetAddressOf());
|
||||
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), 128, 128);
|
||||
|
||||
D2D1Helper.DrawEffect(d2D1DeviceContext.Get(), d2D1Effect.Get());
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[AutoConstructor]
|
||||
private partial struct NullConstantBufferShader : ID2D1PixelShader
|
||||
{
|
||||
private float dummy;
|
||||
|
||||
public float4 Execute()
|
||||
{
|
||||
return dummy;
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする