SkiaSharp: v1.6, CreateSweepGradient, iOS crash

Description

A crash occurs on iOS only when using CreateSweepGradient SkiaSharp/SkiaSharp.Forms v1.6+ to draw a path with DrawPath. The issue does not occur on Android or for SkiaSharp/SkiaSharp.Forms 1.5. The issue only seems to occur if more than 2 colors/points are specified in the gradient.

Code


SKPath lArcPatch = new SKPath();
lArcPatch.AddArc(
    new SKRect(
        mCenterX - (mInnerRadius - mArcOffset), 
        mCenterY - (mInnerRadius - mArcOffset), 
        mCenterX + (mInnerRadius - mArcOffset), 
        mCenterY + (mInnerRadius - mArcOffset)), 
    90 + ((360 - mArcDegrees) / 2),
    mArcDegrees);


SKShader lArcShader = SKShader.CreateSweepGradient(
    new SKPoint(mCenterX, mCenterY),
    new SKColor[] 
    {
        SKColors.Red, SKColors.Red,
        new SKColor(0x00, 0xff, 0x00),
        SKColors.Red, SKColors.Red
    },
    new float[]
    {
        (float)0.0 + lPositionAddr,
        lMinWarnInArc + lPositionAddr,
        (float)((lMaxWarnInArc + lMinWarnInArc) / 2.0) + lPositionAddr,
        lMaxWarnInArc + lPositionAddr,
        (float)1.0
    });

e.Surface.Canvas.DrawPath(
    lArcPatch, 
    new SKPaint() { Style=SKPaintStyle.Stroke, Shader = lArcShader, StrokeWidth = mArcWidth, IsAntialias = true });

Expected Behavior

The path draws with the given gradient.

Actual Behavior

Application crashes

2018-06-27 13:21:41.121 MMR.iOS[4532:7618522] critical: Stacktrace:

2018-06-27 13:21:41.121 MMR.iOS[4532:7618522] critical:   at <unknown> <0xffffffff>
2018-06-27 13:21:41.121 MMR.iOS[4532:7618522] critical:   at (wrapper managed-to-native) SkiaSharp.SkiaApi.sk_canvas_draw_path (intptr,intptr,intptr) <0x00007>
2018-06-27 13:21:41.121 MMR.iOS[4532:7618522] critical:   at SkiaSharp.SKCanvas.DrawPath (SkiaSharp.SKPath,SkiaSharp.SKPaint) [0x0002e] in <dda4dd89ebba425f9972e6db0728b9e9#F95EFE24-1F0F-8FFF-FCDC-11423293DE24>:0
2018-06-27 13:21:41.121 MMR.iOS[4532:7618522] critical:   at XamarinHelpers.Controls.NepGauge.OnPaintSurface (SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs) [0x00609] in C:\Users\jnisewonder\source\repos\CSharp\CommonLibraries\XamarinHelpers\Controls\NepGauge.cs:188
2018-06-27 13:21:41.121 MMR.iOS[4532:7618522] critical:   at SkiaSharp.Views.Forms.SKCanvasView.SkiaSharp.Views.Forms.ISKCanvasViewController.OnPaintSurface (SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs) [0x00002] in <506b88fe480b428d8aa18dffa13375f7#F95EFE24-1F0F-8FFF-FCDC-11423293DE24>:0
2018-06-27 13:21:41.121 MMR.iOS[4532:7618522] critical:   at SkiaSharp.Views.Forms.SKCanvasViewRendererBase`2<TFormsView_REF, TNativeView_REF>.OnPaintSurface (object,SkiaSharp.Views.iOS.SKPaintSurfaceEventArgs) [0x00021] in <506b88fe480b428d8aa18dffa13
375f7#F95EFE24-1F0F-8FFF-FCDC-11423293DE24>:0
2018-06-27 13:21:41.122 MMR.iOS[4532:7618522] critical:   at SkiaSharp.Views.iOS.SKCanvasView.DrawInSurface (SkiaSharp.SKSurface,SkiaSharp.SKImageInfo) [0x00013] in <6bb7f15ce3894ef3bd7d052a3b2395f2#F95EFE24-1F0F-8FFF-FCDC-11423293DE24>:0
2018-06-27 13:21:41.122 MMR.iOS[4532:7618522] critical:   at SkiaSharp.Views.iOS.SKCanvasView.Draw (CoreGraphics.CGRect) [0x0004b] in <6bb7f15ce3894ef3bd7d052a3b2395f2#F95EFE24-1F0F-8FFF-FCDC-11423293DE24>:0
2018-06-27 13:21:41.122 MMR.iOS[4532:7618522] critical:   at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) [0x0001e] in <b238a3153e534349ad10ed0787f2157a#F95EFE24-1F0F-8FFF-FCDC-11423293DE24>:0
2018-06-27 13:21:41.122 MMR.iOS[4532:7618522] critical:   at <unknown> <0xffffffff>
2018-06-27 13:21:41.122 MMR.iOS[4532:7618522] critical:   at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <0x00007>
2018-06-27 13:21:41.122 MMR.iOS[4532:7618522] cr
itical:   at UIKit.UIApplication.Main (string[],intptr,intptr) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/UIKit/UIApplication.cs:79
2018-06-27 13:21:41.122 MMR.iOS[4532:7618522] critical:   at UIKit.UIApplication.Main (string[],string,string) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/UIKit/UIApplication.cs:63
2018-06-27 13:21:41.122 MMR.iOS[4532:7618522] critical:   at MMR.iOS.Application.Main (string[]) [0x00001] in C:\Users\jnisewonder\source\repos\CSharp\MobileMeterReading\MMR\MMR.iOS\Main.cs:17
2018-06-27 13:21:41.122 MMR.iOS[4532:7618522] critical:   at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) [0x0001e] in <b238a3153e534349ad10ed0787f2157a#F95EFE24-1F0F-8FFF-FCDC-11423293DE24>:0
2018-06-27 13:21:41.122 MMR.iOS[4532:7618522] critical: 
Native stacktrace:
2018-06-27 13:21:41.125 MMR.iOS[4532:7618522] critical: 	0   MMR.iOS                             0x0000000104bf4a40 MMR.iOS + 42912320
2018-06-27 13:21:41.125 MMR.iOS[4532:7618522] critical: 	1   MMR.iOS                             0x0000000104bffe5c mono_pmip + 9944
2018-06-27 13:21:41.125 MMR.iOS[4532:7618522] critical: 	2   libsystem_platform.dylib            0x0000000182097b50 _sigtramp + 52
2018-06-27 13:21:41.125 MMR.iOS[4532:7618522] critical: 	3   libSkiaSharp                        0x0000000105511ce0 gr_glinterface_has_extension + 1347152
2018-06-27 13:21:41.125 MMR.iOS[4532:7618522] critical: 	4   libSkiaSharp                        0x0000000105498124 gr_glinterface_has_extension + 848532
2018-06-27 13:21:41.125 MMR.iOS[4532:7618522] critical: 	5   libSkiaSharp                        0x0000000105498028 gr_glinterface_has_extension + 848280
2018-06-27 13:21:41.125 MMR.iOS[4532:7618522] critical: 	6   libSkiaSharp                        0x00000001054adc4c gr_glinterface_has_extension + 937404
2018-06-27 13:21:41.125 MMR.iOS[4532:7618522] critical: 	7   libSkiaSharp                        0x000000010543e0b4 gr_glinterface_has_extensio
n + 479780
2018-06-27 13:21:41.125 MMR.iOS[4532:7618522] critical: 	8   libSkiaSharp                        0x000000010543e38c gr_glinterface_has_extension + 480508
2018-06-27 13:21:41.125 MMR.iOS[4532:7618522] critical: 	9   libSkiaSharp                        0x00000001053d0e90 gr_glinterface_has_extension + 32768
2018-06-27 13:21:41.125 MMR.iOS[4532:7618522] critical: 	10  libSkiaSharp                        0x00000001053e7600 gr_glinterface_has_extension + 124784
2018-06-27 13:21:41.125 MMR.iOS[4532:7618522] critical: 	11  MMR.iOS                             0x00000001039283c0 MMR.iOS + 23200704
2018-06-27 13:21:41.125 MMR.iOS[4532:7618522] critical: 	12  MMR.iOS                             0x00000001038eb1b0 MMR.iOS + 22950320
2018-06-27 13:21:41.125 MMR.iOS[4532:7618522] critical: 	13  MMR.iOS                             0x00000001023bfbf0 MMR.iOS + 752624
2018-06-27 13:21:41.125 MMR.iOS[4532:7618522] critical: 	14  MMR.iOS                             0x00000001039535f0 MMR.iOS + 23377392
2018-06-27 13:
21:41.126 MMR.iOS[4532:7618522] critical: 	15  MMR.iOS                             0x0000000103958968 MMR.iOS + 23398760
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	16  MMR.iOS                             0x000000010396efb4 MMR.iOS + 23490484
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	17  MMR.iOS                             0x000000010396e780 MMR.iOS + 23488384
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	18  MMR.iOS                             0x0000000102a41b48 MMR.iOS + 7576392
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	19  MMR.iOS                             0x0000000104c02eb0 mono_pmip + 22316
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	20  MMR.iOS                             0x0000000104c6aac4 mono_pmip + 447296
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	21  MMR.iOS                             0x0000000104c6e084 mono_pmip + 461056
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	22  MMR.iOS                           
  0x000000010231070c MMR.iOS + 34572
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	23  MMR.iOS                             0x000000010233520c MMR.iOS + 184844
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	24  UIKit                               0x000000018baaec74 <redacted> + 408
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	25  QuartzCore                          0x00000001864b751c <redacted> + 296
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	26  QuartzCore                          0x00000001863ae954 <redacted> + 232
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	27  QuartzCore                          0x00000001864bd2ac <redacted> + 52
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	28  QuartzCore                          0x00000001864b6f48 <redacted> + 1672
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	29  QuartzCore                          0x00000001864283d4 <redacted> + 520
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 
	30  QuartzCore                          0x000000018644fb40 <redacted> + 540
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	31  QuartzCore                          0x00000001863a174c <redacted> + 928
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	32  QuartzCore                          0x0000000186455c0c <redacted> + 240
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	33  CoreFoundation                      0x0000000182401090 <redacted> + 188
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	34  CoreFoundation                      0x000000018241be00 <redacted> + 56
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	35  CoreFoundation                      0x000000018241b504 <redacted> + 440
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	36  CoreFoundation                      0x0000000182418fd8 <redacted> + 2196
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	37  CoreFoundation                      0x0000000182338c58 CFRunLoopRunSpecific + 436
2018-0
6-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	38  GraphicsServices                    0x00000001841e4f84 GSEventRunModal + 100
2018-06-27 13:21:41.126 MMR.iOS[4532:7618522] critical: 	39  UIKit                               0x000000018ba915c4 UIApplicationMain + 236
2018-06-27 13:21:41.127 MMR.iOS[4532:7618522] critical: 	40  MMR.iOS                             0x00000001036b2cd0 MMR.iOS + 20622544
2018-06-27 13:21:41.127 MMR.iOS[4532:7618522] critical: 	41  MMR.iOS                             0x000000010363991c MMR.iOS + 20125980
2018-06-27 13:21:41.127 MMR.iOS[4532:7618522] critical: 	42  MMR.iOS                             0x00000001036398dc MMR.iOS + 20125916
2018-06-27 13:21:41.127 MMR.iOS[4532:7618522] critical: 	43  MMR.iOS                             0x0000000102683d80 MMR.iOS + 3652992
2018-06-27 13:21:41.127 MMR.iOS[4532:7618522] critical: 	44  MMR.iOS                             0x0000000102a41b48 MMR.iOS + 7576392
2018-06-27 13:21:41.127 MMR.iOS[4532:7618522] critical: 	45  MMR.iOS           
                  0x0000000104c02eb0 mono_pmip + 22316
2018-06-27 13:21:41.127 MMR.iOS[4532:7618522] critical: 	46  MMR.iOS                             0x0000000104c6aac4 mono_pmip + 447296
2018-06-27 13:21:41.127 MMR.iOS[4532:7618522] critical: 	47  MMR.iOS                             0x0000000104c6fcc8 mono_pmip + 468292
2018-06-27 13:21:41.127 MMR.iOS[4532:7618522] critical: 	48  MMR.iOS                             0x0000000104beb300 MMR.iOS + 42873600
2018-06-27 13:21:41.127 MMR.iOS[4532:7618522] critical: 	49  MMR.iOS                             0x0000000104d14fbc _Z9__isctypeim + 47160
2018-06-27 13:21:41.127 MMR.iOS[4532:7618522] critical: 	50  MMR.iOS                             0x0000000102339014 MMR.iOS + 200724
2018-06-27 13:21:41.127 MMR.iOS[4532:7618522] critical: 	51  libdyld.dylib                       0x0000000181e5856c <redacted> + 4
2018-06-27 13:21:41.127 MMR.iOS[4532:7618522] critical: 
=================================================================
Got a SIGSEGV while executing native c
ode. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

Basic Information

  • Version with issue: 1.60.1
  • Last known good version: 1.59.3
  • IDE: Visual Studio 2017
  • Platform Target Frameworks:
    • iOS: 11.1
  • Target Devices: iPad Pro

Screenshots

Reproduction Link

VS bug #738687

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 16 (9 by maintainers)

Most upvoted comments

I have the same issue. 100% reproduce by invalidating canvas view and redraw

For those either 1. Still suffering from this issue or 2. Using an older version of SkiaSharp and cannot update for whatever reason:

On a project where I work, we were running into this (We are forced to user an older version of SkiaSharp). It seems to be something with the handling of floating point handing under the hood.

Our solution was to use something along the lines of:

float CenterX = (float)Math.Round(bounds.Width / 2.0, 2, MidpointRounding.ToEven);
float CenterY = (float)Math.Round(bounds.Height / 2.0, 2, MidpointRounding.ToEven);
var shader = SKShader.CreateSweepGradient(new SKPoint(CenterX, CenterY), colors, new float[] { 0.0F, (float)Math.Round(<SomePercentage>, 2, MidpointRounding.ToEven) });

Our use case is a circle where the color changes depending on a percentage. We’ve noticed that older versions of SkiaSharp don’t handle certain floating point numbers very well. We’ve had fairly good success with this rounding method though (even though it’s obviously not ideal).

Appears so. That is very worrying. But, I did update Xcode on my local machine. I’m building on CI now. If the problem comes back from that artifacts, then it may be a clang optimization issue that was fixed on the new Xcode. I shall check and track it.

This has happened before, mostly on Android though. And Linux.