Mapsui icon indicating copy to clipboard operation
Mapsui copied to clipboard

App crash because of SkiaSharp version for Mapsui 2.0.3

Open johnhs91 opened this issue 5 years ago • 12 comments

Hello

Crash issue with SkiaSharp and maybe Mapsui.

Before I used Mapsui source (2.0.0-beta.30), and skiasharp 1.68.1.1. This had a bug as the map sometimes freeze 100%. After updating to 2.0.3 it fixed the freeze problem. (Updated SkiaSharp aswell because of this) But after this update, the app started to crash. For what I belive is a bug in SkiaSharp. But since I can't find source for mapsui 2.0.3, I had to use nuget instead, and it require SkiaSharp 1.68.2.1+, since this update.

I've tried to reproduce the error myself alot of times, but it's hard. Got it once, while I didn't debug sadly. But it happends like 10+ times a day. (500+ users)

All info I get of the crash is this:

Error: Application.Main (System.String[] args) SIGABRT: Cannot access a disposed object. Object name: 'SKGLView'.

Only stacktrace I get is this: NSObject.get_SuperHandle () GLKView.Display () SKGLViewRenderer+<>c__DisplayClass4_0.<SetupRenderLoop>b__1 () NSAsyncActionDispatcher.Apply () (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) Application.Main (System.String[] args)

My best idea is it's a SkiaSharp bug. But impossible to fix for me, since I can't update the version. Only thing that use SkiaSharp is Mapsui.

Any idea or help would be awesome!

johnhs91 avatar Nov 04 '20 13:11 johnhs91

If I search specific on SKGLView it's about SkiaSharp. But can this be caused by Xamarin.Forms version maybe? My knowledge of Xamarin.forms rendere isn't good. So I could be wrong in believing it's about SkiaSharp ?

johnhs91 avatar Nov 04 '20 14:11 johnhs91

Didn't help to update XF to latest. Still got same crash.

johnhs91 avatar Nov 05 '20 10:11 johnhs91

Looks like it's related to this: https://github.com/xamarin/Xamarin.Forms/issues/11319

So looks like it's a SkiaSharp bug.

johnhs91 avatar Nov 05 '20 11:11 johnhs91

I can reproduce by making my app go to sleep, wait a while. Then startup. So it get disposed in background, and when opening again, it crash.

It's a SkiaSharp error, but can't see any changes to the renderer, so I'm really lost.

johnhs91 avatar Nov 05 '20 14:11 johnhs91

The source of Mapsui 2.0.3 is in the release/2.0 branch https://github.com/Mapsui/Mapsui/tree/release/2.0

The alpha release has a newer version of SkiaSharp, could it be fixed there?

pauldendulk avatar Nov 10 '20 06:11 pauldendulk

I found 2.0.3 source, in tags. I'm not a github expert, so took some time.

I'm currently trying to build everything with source code of mapsui 2.0.3 and Skiasharp 1.68.3 source code. To see if I get better information.

I've been looking at SkiaSharp's renderer that crash, and the few changes from 1.68.1.1 till 2.80.x can't create these crashes. So I'm abit confused atm.

Could try just to update to alpha, even though I'm not happy by using alpha versions. Did you change alot from 2.0.3 till 3.0.0 ?

johnhs91 avatar Nov 10 '20 07:11 johnhs91

The alpha would be just for testing. If the newer skiasharp version fixes your problem then I will upgrade v2 as well.

pauldendulk avatar Nov 10 '20 07:11 pauldendulk

So I've searched some more. And found out the problem is specific in line 60 in here: https://github.com/mono/SkiaSharp/blob/master/source/SkiaSharp.Views.Forms/SkiaSharp.Views.Forms.iOS/SKGLViewRenderer.cs

Meaning it's on app coming foreground, it run a renderer once. (Oneshot) and because control have been disposed in background, it crash here. This have always been like this in SkiaSharp, and is so in newest version, so is it posible some lifecycle of mapsui have been changed, so it sometimes don't recreate control before redraw?

Don't know if it makes sense, but hard for me to give you source that can reproduce.

Problem here is, it happens rarely, so hard just to check if fixed. Wish I had a way to check if disposed, then ill just add it in skiasharp.

johnhs91 avatar Nov 13 '20 07:11 johnhs91

So I've searched some more. And found out the problem is specific in line 60 in here: https://github.com/mono/SkiaSharp/blob/master/source/SkiaSharp.Views.Forms/SkiaSharp.Views.Forms.iOS/SKGLViewRenderer.cs

Meaning it's on app coming foreground, it run a renderer once. (Oneshot) and because control have been disposed in background, it crash here.

Thank you for your detailed analysis.

This have always been like this in SkiaSharp, and is so in newest version

Did you test this in Mapsui 3.0.0-alpha.3, using SkiaSharp 2.80.2?

pauldendulk avatar Nov 13 '20 08:11 pauldendulk

No, took me 10 hours to get more analyse data from build with source code from both.

I can try to set it up with latest alpha mapsui and skia 2.80. And test rest of the day. But not even secure to get the crash in that time

johnhs91 avatar Nov 13 '20 08:11 johnhs91

No, took me 10 hours to get more analyse data from build with source code from both.

Which 'both'?

pauldendulk avatar Nov 13 '20 12:11 pauldendulk

I mean I build my app with source code from both SkiaSharp source and Mapsui source. (Instead of nuget) So I was able to get better debug information.

johnhs91 avatar Nov 13 '20 18:11 johnhs91

Now that v4 is out the situation is completely different. I will close this.

pauldendulk avatar Jun 23 '23 19:06 pauldendulk