Skip to content

Commit 687b78d

Browse files
committed
Fix crash on degenerate curves
1 parent 8dd7dbf commit 687b78d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

Sources/vger/vger.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ void vgerStrokeBezier(vgerContext vg, vgerBezierSegment s, float width, vgerPain
264264
float2 d1 = rot90 * width * normalize(s.c - s.a);
265265
float2 d2 = rot90 * width * normalize(s.c - s.b);
266266

267+
// Don't render degenerate curves.
268+
if (any(isnan(d0)) || any(isnan(d1)) || any(isnan(d2))) {
269+
return;
270+
}
271+
267272
vgerMoveTo(vg, s.a - d0);
268273
vgerQuadTo(vg, s.b - d1, s.c - d2);
269274
vgerLineTo(vg, s.c + d2);

Tests/vgerTests/vgerTests.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ - (void) testBasic {
136136

137137
vgerFillCircle(vg, float2{256, 256}, 40, cyan);
138138
vgerStrokeBezier(vg, {{256,256}, {256,384}, {384,384}}, 1, white);
139+
vgerStrokeBezier(vg, {{384,384}, {512,512}, {512,512}}, 1, white); // Degenerate
139140
vgerFillRect(vg, float2{400,100}, float2{450,150}, 10, vgerLinearGradient(vg, float2{400,100}, float2{450, 150}, float4{0,1,1,1}, float4{1,0,1,1}, 0));
140141
vgerFillRect(vg, float2{400,200}, float2{450,250}, 10, vgerRadialGradient(vg, float2{425,225}, 10, 40, float4{0,1,1,1}, float4{1,0,1,1}, 0));
141142
vgerStrokeArc(vg, float2{100,400}, 30, 3, theta, ap, white);

0 commit comments

Comments
 (0)