Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.6, CreateSweepGradient, iOS crash #569

Closed
jnisewonder opened this issue Jun 27, 2018 · 16 comments

Comments

Projects
8 participants
@jnisewonder
Copy link

commented Jun 27, 2018

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

@mattleibow mattleibow added this to New in Triage Jul 26, 2018

@duyduong

This comment has been minimized.

Copy link

commented Aug 31, 2018

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

@mattleibow

This comment has been minimized.

Copy link
Contributor

commented Oct 4, 2018

I was not able to reproduce this. Are you able to attach a small repro or maybe the values that it crashes on?

It may be the case that something is zero or out of order. If this is the case, I probably need to add some more error checking to make sure it doesn't just crash randomly, but does so with a real .NET exception.

@mattleibow mattleibow added the need-info label Oct 4, 2018

@Suplanus

This comment has been minimized.

Copy link

commented Nov 22, 2018

Here is a small app with the issue:
https://github.com/jsuarezruiz/MyTripCountdown

The crash raised after a minute not at the first draw.

@mattleibow mattleibow moved this from New to Needs Info in Triage Nov 23, 2018

@Redth Redth moved this from Needs Info to Needs Triage in Triage Nov 27, 2018

@Redth Redth removed the need-info label Nov 28, 2018

@mattleibow mattleibow moved this from Needs Triage to High Priority in Triage Nov 30, 2018

@Redth Redth moved this from High Priority to Needs Triage in Triage Dec 1, 2018

@mattleibow

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2018

This is something that we will be looking at in the future.

@mattleibow mattleibow moved this from Needs Triage to High Priority in Triage Dec 4, 2018

@thisisthekap

This comment has been minimized.

Copy link

commented Dec 21, 2018

Same issue here. Also 100% reproducible. Also reproducible using 1.68.

@Redth Redth moved this from High Priority to Needs Triage in Triage Dec 21, 2018

@mattleibow

This comment has been minimized.

Copy link
Contributor

commented Dec 21, 2018

All right. I finally managed to reproduce this. It has to be a physical device running the later versions of iOS.
In an effort to find out what was crashing, I enabled the generation of the dSYM (#742) - which is actually good for everyone.

Now, the app no longer crashes. No idea what caused the crash, but it is "fixed". Once the PR builds and is merged, then I will release a preview to see if that solves all the problems for everyone.

Thanks for reporting this issue, the world is soon going to be (hopefully) a better place.

@mattleibow mattleibow moved this from Needs Triage to High Priority in Triage Dec 21, 2018

@mattleibow mattleibow added this to To do in v1.68.1 via automation Dec 21, 2018

@mattleibow mattleibow removed this from High Priority in Triage Dec 21, 2018

@mattleibow mattleibow moved this from To do to In progress in v1.68.1 Dec 21, 2018

@thisisthekap

This comment has been minimized.

Copy link

commented Dec 21, 2018

@mattleibow So the issue was "fixed" by enabling the generation of dSYM?

@mattleibow

This comment has been minimized.

Copy link
Contributor

commented Dec 21, 2018

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.

@Redth Redth added this to Needs Triage in Triage Dec 22, 2018

@mattleibow

This comment has been minimized.

Copy link
Contributor

commented Dec 29, 2018

Sadly, no deal. I am still having a look at this - I thought things were working, but it is very deceiving. The crashes are very random, and the app still seems to "run" (more like just exist) after the crash.
Very random. Sometimes the app will run fine for a minute, other times it crashes before the timer even ticks. I am trying to isolate the cause, maybe something is getting disposed mid-draw.
Will keep you updated.

@mattleibow

This comment has been minimized.

Copy link
Contributor

commented Dec 29, 2018

RIGHT! Solutions!

So, I figured out what was happening - at least on my side. I believe that the NuGet update was not actually going through and it was still using v1.60.x. As a result, the issue was still from the previous release. I am not sure what the fix was since it is 8 releases later, and many compiler changes, but v1.68.x is working.

When you update the NuGet, make sure to delete the obj/bin from all the solution projects. I am not sure if this is a NuGet or Visual Studio issue, but it actually does not use the new native files.

The way I found this out was when trying a SKGLView view to see if this was just a raster bug or affects GPU as well. I then got an "entrypoint not found" exception for something that should be there as it was added to the initial 1.68.x release.

@mattleibow mattleibow closed this Dec 29, 2018

Triage automation moved this from Needs Triage to Done Dec 29, 2018

v1.68.1 automation moved this from In progress to Done Dec 29, 2018

@mattleibow mattleibow removed this from Done in Triage Dec 29, 2018

@mattleibow mattleibow removed this from Done in v1.68.1 Dec 29, 2018

@mattleibow mattleibow added this to Done in v1.68.0 Dec 29, 2018

@mattleibow

This comment has been minimized.

Copy link
Contributor

commented Dec 29, 2018

If this is still an issue, just re-open.

@NirmalSubedi17

This comment has been minimized.

Copy link

commented Jan 16, 2019

This is still crashing sometimes! We never know when it does crash though. Using the latest version of Xamarin Forms and SkiaSharp (1.68...) . Getting the exact same issue!
I'm using the very fast timer of 10 miliseconds to produce the circle while user touches on the screen until it makes complete circle.

@mattleibow

This comment has been minimized.

Copy link
Contributor

commented Jan 17, 2019

@NirmalSubedi17 Is this happening with the countdown timer app? Are you able to attach a repro if it is happening for you, but not the countdown app?

@NirmalSubedi17

This comment has been minimized.

Copy link

commented Jan 17, 2019

@mattleibow I copied the same Circular Progress Control. I didn't modified that control at all. I'm starting the Progress if user touch some button. While he keeps touching the button; I start the timer (10 milisec) and it increases the Progress by 0.01f only!
If he keeps holding that button until the progress get 1 (100%) then we do something else. But if user leaves the touch before it reaches 100% then it will reset again to 0. and so forth.

It was crashing yesterday; Now i just tried crashing it but it's not. Its a same build! Nothing changed except the days that I'm testing! Weird!

@mattleibow

This comment has been minimized.

Copy link
Contributor

commented Jan 18, 2019

I also noticed the issue because after I updated, the IDE kept using the old native library - which had the issue. Did you update recently? If so, did you actually do a clean and rebuild? Or have you restarted VS since the update?

@David-Lamar

This comment has been minimized.

Copy link

commented May 15, 2019

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.