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

Commit dad72d3

Browse files
Fixed issue creating Paths with segments without points on iOS (#13161)
Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
1 parent 430754b commit dad72d3

File tree

3 files changed

+130
-3
lines changed

3 files changed

+130
-3
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
using Xamarin.Forms.CustomAttributes;
2+
using Xamarin.Forms.Internals;
3+
using Xamarin.Forms.Shapes;
4+
5+
#if UITEST
6+
using Xamarin.UITest;
7+
using NUnit.Framework;
8+
using Xamarin.Forms.Core.UITests;
9+
#endif
10+
11+
namespace Xamarin.Forms.Controls.Issues
12+
{
13+
[Preserve(AllMembers = true)]
14+
[Issue(IssueTracker.Github, 13159, "[Bug] +Fix. Path.Data crashing when geometry has a PolyLineSegment with 0 point",
15+
PlatformAffected.iOS)]
16+
#if UITEST
17+
[Category(UITestCategories.Shape)]
18+
#endif
19+
public class Issue13159 : TestContentPage
20+
{
21+
const string TestReady = "TestReadyId";
22+
23+
public Issue13159()
24+
{
25+
26+
}
27+
28+
protected override void Init()
29+
{
30+
var layout = new StackLayout();
31+
32+
var instructions = new Label
33+
{
34+
AutomationId = TestReady,
35+
Padding = 12,
36+
BackgroundColor = Color.Black,
37+
TextColor = Color.White,
38+
Text = "Without exceptions, the test has passed."
39+
};
40+
41+
layout.Children.Add(instructions);
42+
layout.Children.Add(CreateNoPointsPolyLineSegmentPath());
43+
layout.Children.Add(CreateNoPointsPolyBezierSegmentPath());
44+
layout.Children.Add(CreateNoPointsPolyQuadraticBezierSegmentPath());
45+
layout.Children.Add(CreateNoPointsArcSegmentPath());
46+
47+
Content = layout;
48+
}
49+
50+
Path CreateNoPointsPolyLineSegmentPath()
51+
{
52+
var path = new Path();
53+
54+
PathFigure pathFigure = new PathFigure();
55+
56+
pathFigure.Segments.Add(new PolyLineSegment());
57+
58+
PathGeometry geometry = new PathGeometry();
59+
60+
geometry.Figures.Add(pathFigure);
61+
62+
path.Data = geometry;
63+
64+
return path;
65+
}
66+
67+
Path CreateNoPointsPolyBezierSegmentPath()
68+
{
69+
var path = new Path();
70+
71+
PathFigure pathFigure = new PathFigure();
72+
73+
pathFigure.Segments.Add(new PolyBezierSegment());
74+
75+
PathGeometry geometry = new PathGeometry();
76+
77+
geometry.Figures.Add(pathFigure);
78+
79+
path.Data = geometry;
80+
81+
return path;
82+
}
83+
84+
Path CreateNoPointsPolyQuadraticBezierSegmentPath()
85+
{
86+
var path = new Path();
87+
88+
PathFigure pathFigure = new PathFigure();
89+
90+
pathFigure.Segments.Add(new PolyQuadraticBezierSegment());
91+
92+
PathGeometry geometry = new PathGeometry();
93+
94+
geometry.Figures.Add(pathFigure);
95+
96+
path.Data = geometry;
97+
98+
return path;
99+
}
100+
101+
Path CreateNoPointsArcSegmentPath()
102+
{
103+
var path = new Path();
104+
105+
PathFigure pathFigure = new PathFigure();
106+
107+
pathFigure.Segments.Add(new ArcSegment());
108+
109+
PathGeometry geometry = new PathGeometry();
110+
111+
geometry.Figures.Add(pathFigure);
112+
113+
path.Data = geometry;
114+
115+
return path;
116+
}
117+
118+
#if UITEST && __IOS__
119+
[Test]
120+
public void Issue13159NoPointsPathTest()
121+
{
122+
RunningApp.WaitForElement(TestReady);
123+
}
124+
#endif
125+
}
126+
}

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,7 @@
17941794
<Compile Include="$(MSBuildThisFileDirectory)Issue8833.xaml.cs" />
17951795
<Compile Include="$(MSBuildThisFileDirectory)Issue10086.xaml.cs" />
17961796
<Compile Include="$(MSBuildThisFileDirectory)Issue13136.xaml.cs" />
1797+
<Compile Include="$(MSBuildThisFileDirectory)Issue13159.cs" />
17971798
<Compile Include="$(MSBuildThisFileDirectory)Issue11980.cs" />
17981799
<Compile Include="$(MSBuildThisFileDirectory)Issue13173.xaml.cs" />
17991800
<Compile Include="$(MSBuildThisFileDirectory)Issue8282.xaml.cs" />

Xamarin.Forms.Platform.iOS/Extensions/GeometryExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static PathData ToCGPath(this Geometry geometry, Transform renderTransfor
9090
for (int i = 0; i < points.Count; i++)
9191
pathData.Data.AddLineToPoint(transform, points[i].ToPointF());
9292

93-
lastPoint = points[points.Count - 1];
93+
lastPoint = points.Count > 0 ? points[points.Count - 1] : Point.Zero;
9494
}
9595
// BezierSegment
9696
else if (pathSegment is BezierSegment)
@@ -123,7 +123,7 @@ public static PathData ToCGPath(this Geometry geometry, Transform renderTransfor
123123
}
124124
}
125125

126-
lastPoint = points[points.Count - 1];
126+
lastPoint = points.Count > 0 ? points[points.Count - 1] : Point.Zero;
127127
}
128128
// QuadraticBezierSegment
129129
else if (pathSegment is QuadraticBezierSegment)
@@ -158,7 +158,7 @@ public static PathData ToCGPath(this Geometry geometry, Transform renderTransfor
158158
}
159159
}
160160

161-
lastPoint = points[points.Count - 1];
161+
lastPoint = points.Count > 0 ? points[points.Count - 1] : Point.Zero;
162162
}
163163
// ArcSegment
164164
else if (pathSegment is ArcSegment)

0 commit comments

Comments
 (0)