diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue13159.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue13159.cs new file mode 100644 index 00000000000..ea899651f56 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue13159.cs @@ -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 + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index ae9e1c4915b..c463c8185fb 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -1794,6 +1794,7 @@ + diff --git a/Xamarin.Forms.Platform.iOS/Extensions/GeometryExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/GeometryExtensions.cs index 89ed08fc37f..2c618384cd5 100644 --- a/Xamarin.Forms.Platform.iOS/Extensions/GeometryExtensions.cs +++ b/Xamarin.Forms.Platform.iOS/Extensions/GeometryExtensions.cs @@ -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) @@ -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) @@ -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)