Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Fixed issue creating Paths with segments without points on iOS (#13161)
Browse files Browse the repository at this point in the history
Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
  • Loading branch information
jsuarezruiz and jfversluis authored Nov 9, 2023
1 parent 430754b commit dad72d3
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Shapes;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 13159, "[Bug] +Fix. Path.Data crashing when geometry has a PolyLineSegment with 0 point",
PlatformAffected.iOS)]
#if UITEST
[Category(UITestCategories.Shape)]
#endif
public class Issue13159 : TestContentPage
{
const string TestReady = "TestReadyId";

public Issue13159()
{

}

protected override void Init()
{
var layout = new StackLayout();

var instructions = new Label
{
AutomationId = TestReady,
Padding = 12,
BackgroundColor = Color.Black,
TextColor = Color.White,
Text = "Without exceptions, the test has passed."
};

layout.Children.Add(instructions);
layout.Children.Add(CreateNoPointsPolyLineSegmentPath());
layout.Children.Add(CreateNoPointsPolyBezierSegmentPath());
layout.Children.Add(CreateNoPointsPolyQuadraticBezierSegmentPath());
layout.Children.Add(CreateNoPointsArcSegmentPath());

Content = layout;
}

Path CreateNoPointsPolyLineSegmentPath()
{
var path = new Path();

PathFigure pathFigure = new PathFigure();

pathFigure.Segments.Add(new PolyLineSegment());

PathGeometry geometry = new PathGeometry();

geometry.Figures.Add(pathFigure);

path.Data = geometry;

return path;
}

Path CreateNoPointsPolyBezierSegmentPath()
{
var path = new Path();

PathFigure pathFigure = new PathFigure();

pathFigure.Segments.Add(new PolyBezierSegment());

PathGeometry geometry = new PathGeometry();

geometry.Figures.Add(pathFigure);

path.Data = geometry;

return path;
}

Path CreateNoPointsPolyQuadraticBezierSegmentPath()
{
var path = new Path();

PathFigure pathFigure = new PathFigure();

pathFigure.Segments.Add(new PolyQuadraticBezierSegment());

PathGeometry geometry = new PathGeometry();

geometry.Figures.Add(pathFigure);

path.Data = geometry;

return path;
}

Path CreateNoPointsArcSegmentPath()
{
var path = new Path();

PathFigure pathFigure = new PathFigure();

pathFigure.Segments.Add(new ArcSegment());

PathGeometry geometry = new PathGeometry();

geometry.Figures.Add(pathFigure);

path.Data = geometry;

return path;
}

#if UITEST && __IOS__
[Test]
public void Issue13159NoPointsPathTest()
{
RunningApp.WaitForElement(TestReady);
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue8833.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue10086.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13136.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13159.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11980.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13173.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8282.xaml.cs" />
Expand Down
6 changes: 3 additions & 3 deletions Xamarin.Forms.Platform.iOS/Extensions/GeometryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static PathData ToCGPath(this Geometry geometry, Transform renderTransfor
for (int i = 0; i < points.Count; i++)
pathData.Data.AddLineToPoint(transform, points[i].ToPointF());

lastPoint = points[points.Count - 1];
lastPoint = points.Count > 0 ? points[points.Count - 1] : Point.Zero;
}
// BezierSegment
else if (pathSegment is BezierSegment)
Expand Down Expand Up @@ -123,7 +123,7 @@ public static PathData ToCGPath(this Geometry geometry, Transform renderTransfor
}
}

lastPoint = points[points.Count - 1];
lastPoint = points.Count > 0 ? points[points.Count - 1] : Point.Zero;
}
// QuadraticBezierSegment
else if (pathSegment is QuadraticBezierSegment)
Expand Down Expand Up @@ -158,7 +158,7 @@ public static PathData ToCGPath(this Geometry geometry, Transform renderTransfor
}
}

lastPoint = points[points.Count - 1];
lastPoint = points.Count > 0 ? points[points.Count - 1] : Point.Zero;
}
// ArcSegment
else if (pathSegment is ArcSegment)
Expand Down

0 comments on commit dad72d3

Please sign in to comment.