Skip to content

Commit

Permalink
Fixing issue #1187 (#1206)
Browse files Browse the repository at this point in the history
* Passing null to SkPathMeasure results in AccessViolationException

Co-authored-by: Ziriax <[email protected]>
  • Loading branch information
mattleibow and ziriax authored Apr 2, 2020
1 parent 6890178 commit 234c93a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion binding/Binding/SKPathMeasure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ public SKPathMeasure ()
}

public SKPathMeasure (SKPath path, bool forceClosed = false, float resScale = 1)
: this (SkiaApi.sk_pathmeasure_new_with_path (path == null ? IntPtr.Zero : path.Handle, forceClosed, resScale), true)
: this (IntPtr.Zero, true)
{
if (path == null)
throw new ArgumentNullException (nameof (path));

Handle = SkiaApi.sk_pathmeasure_new_with_path (path.Handle, forceClosed, resScale);

if (Handle == IntPtr.Zero) {
throw new InvalidOperationException ("Unable to create a new SKPathMeasure instance.");
}
Expand Down
30 changes: 30 additions & 0 deletions tests/Tests/SKPathMeasureTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using Xunit;

namespace SkiaSharp.Tests
{
public class SKPathMeasureTest : SKTest
{
[SkippableFact]
public void ConstructorThrowsOnNullPathArgument()
{
var ex = Assert.Throws<ArgumentNullException>(() => new SKPathMeasure(null));
Assert.Equal("path", ex.ParamName);
}

[SkippableFact]
public void ConstructorDoesNotThrownOnNonNullPathArgument()
{
var path = new SKPath();
var pm = new SKPathMeasure(path);
Assert.NotNull(pm);
}

[SkippableFact]
public void EmptyConstructorDoesNotThrow()
{
var pm = new SKPathMeasure();
Assert.NotNull(pm);
}
}
}

0 comments on commit 234c93a

Please sign in to comment.