diff --git a/android/src/main/java/com/horcrux/svg/Brush.java b/android/src/main/java/com/horcrux/svg/Brush.java index b22d760d7..88c8d0381 100644 --- a/android/src/main/java/com/horcrux/svg/Brush.java +++ b/android/src/main/java/com/horcrux/svg/Brush.java @@ -154,7 +154,12 @@ void setupPaint(Paint paint, RectF pathBoundingBox, float scale, float opacity) return; } - int stopsCount = mColors.size() / 2; + int size = mColors.size(); + if (size == 0) { + FLog.w(ReactConstants.TAG, "Gradient contains no stops"); + return; + } + int stopsCount = size / 2; int[] stopsColors = new int[stopsCount]; float[] stops = new float[stopsCount]; parseGradientStops(mColors, stopsCount, stops, stopsColors, opacity); @@ -167,7 +172,7 @@ void setupPaint(Paint paint, RectF pathBoundingBox, float scale, float opacity) // editors or other tools, so let's handle that gracefully. stopsColors = new int[] { stopsColors[0], stopsColors[0] }; stops = new float[] { stops[0], stops[0] }; - FLog.w(ReactConstants.TAG, "Gradient contains only on stop"); + FLog.w(ReactConstants.TAG, "Gradient contains only one stop"); } if (mType == BrushType.LINEAR_GRADIENT) { diff --git a/ios/Brushes/RNSVGPainter.m b/ios/Brushes/RNSVGPainter.m index eb4602433..e37064e53 100644 --- a/ios/Brushes/RNSVGPainter.m +++ b/ios/Brushes/RNSVGPainter.m @@ -187,6 +187,10 @@ - (void)paintPattern:(CGContextRef)context bounds:(CGRect)bounds - (void)paintLinearGradient:(CGContextRef)context bounds:(CGRect)bounds { + if ([_colors count] == 0) { + RCTLogWarn(@"No stops in gradient"); + return; + } CGGradientRef gradient = CGGradientRetain([RCTConvert RNSVGCGGradient:_colors]); CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation; @@ -208,6 +212,10 @@ - (void)paintLinearGradient:(CGContextRef)context bounds:(CGRect)bounds - (void)paintRadialGradient:(CGContextRef)context bounds:(CGRect)bounds { + if ([_colors count] == 0) { + RCTLogWarn(@"No stops in gradient"); + return; + } CGGradientRef gradient = CGGradientRetain([RCTConvert RNSVGCGGradient:_colors]); CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation;