Mapsui: [Forms][beta-28/30/master] OnPaintSurface NullReferenceException

Created on 27 Nov 2019  路  17Comments  路  Source: Mapsui/Mapsui

Hello, not sure if Mapsui or SkiaSharp problem, but I'm facing this after updating Mapsui from beta-22 to beta-28/30 or even after downloading source from master and referencing this in my project.

Affected with
Xamarin Forms 4.3
Mapsui beta-28/beta-30/master

Reproduction project
The same behavior appears in my main project, so I created simple project to show this. Displaying map is exactly the same as I have in my project (I mean this ContentView, etc.)
https://github.com/jabools/mapsui-exception

Reproduction steps

  1. Go to Map from side menu
  2. Go back to About
  3. Go to Map again, and it will crash

Stacktrace

11-27 18:54:44.469 E/mono    (29129): Unhandled Exception:
11-27 18:54:44.469 E/mono    (29129): System.NullReferenceException: Object reference not set to an instance of an object.
11-27 18:54:44.469 E/mono    (29129):   at SkiaSharp.Views.Android.SKGLTextureViewRenderer.get_CanvasSize () [0x00000] in <c472e4808aa44f04aff13ad4b12cbbac>:0 
11-27 18:54:44.469 E/mono    (29129):   at SkiaSharp.Views.Android.SKGLTextureView.get_CanvasSize () [0x00000] in <c472e4808aa44f04aff13ad4b12cbbac>:0 
11-27 18:54:44.469 E/mono    (29129):   at SkiaSharp.Views.Forms.SKGLViewRendererBase`2[TFormsView,TNativeView].OnGetCanvasSize (System.Object sender, SkiaSharp.Views.Forms.GetPropertyValueEventArgs`1[T] e) [0x00007] in <744e5c462db84bf7969e9620360e34f4>:0 
11-27 18:54:44.469 E/mono    (29129):   at (wrapper delegate-invoke) System.EventHandler`1[SkiaSharp.Views.Forms.GetPropertyValueEventArgs`1[SkiaSharp.SKSize]].invoke_void_object_TEventArgs(object,SkiaSharp.Views.Forms.GetPropertyValueEventArgs`1<SkiaSharp.SKSize>)
11-27 18:54:44.469 E/mono    (29129):   at SkiaSharp.Views.Forms.SKGLView.get_CanvasSize () [0x00010] in <744e5c462db84bf7969e9620360e34f4>:0 
11-27 18:54:44.469 E/mono    (29129):   at Mapsui.UI.Forms.MapControl.OnPaintSurface (System.Object sender, SkiaSharp.Views.Forms.SKPaintGLSurfaceEventArgs skPaintSurfaceEventArgs) [0x00000] in <628579b00c104b96ab9d59182f6ee335>:0 
11-27 18:54:44.469 E/mono    (29129):   at SkiaSharp.Views.Forms.SKGLView.OnPaintSurface (SkiaSharp.Views.Forms.SKPaintGLSurfaceEventArgs e) [0x0000a] in <744e5c462db84bf7969e9620360e34f4>:0 
11-27 18:54:44.469 E/mono    (29129):   at SkiaSharp.Views.Forms.SKGLView.SkiaSharp.Views.Forms.ISKGLViewController.OnPaintSurface (SkiaSharp.Views.Forms.SKPaintGLSurfaceEventArgs e) [0x00000] in <744e5c462db84bf7969e9620360e34f4>:0 
11-27 18:54:44.469 E/mono    (29129):   at SkiaSharp.Views.Forms.SKGLViewRendererBase`2[TFormsView,TNativeView].OnPaintSurface (System.Object sender, SkiaSharp.Views.Android.SKPaintGLSurfaceEventArgs e) [0x00021] in <744e5c462db84bf7969e9620360e34f4>:0 
11-27 18:54:44.469 E/mono    (29129):   at SkiaSharp.Views.Android.SKGLTextureView.OnPaintSurface (SkiaSharp.Views.Android.SKPaintGLSurfaceEventArgs e) [0x0000a] in <c472e4808aa44f04aff13ad4b12cbbac>:0 
11-27 18:54:44.469 E/mono    (29129):   at SkiaSharp.Views.Android.SKGLTextureView+InternalRenderer.OnPaintSurface (SkiaSharp.Views.Android.SKPaintGLSurfaceEventArgs e) [0x00000] in <c472e4808aa44f04aff13ad4b12cbbac>:0 
11-27 18:54:44.469 E/mono    (29129):   at SkiaSharp.Views.Android.SKGLTextureViewRenderer.OnDrawFrame (Javax.Microedition.Khronos.Opengles.IGL10 gl) [0x00116] in <c472e4808aa44f04aff13ad4b12cbbac>:0 
11-27 18:54:44.469 E/mono    (29129):   at SkiaSharp.Views.Android.GLTextureView+GLThread.GuardedRun () [0x003b5] in <c472e4808aa44f04aff13ad4b12cbbac>:0 
11-27 18:54:44.469 E/mono    (29129):   at SkiaSharp.Views.Android.GLTextureView+GLThread.Run () [0x00025] in <c472e4808aa44f04aff13ad4b12cbbac>:0 
11-27 18:54:44.469 E/mono    (29129):   at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00014] in <3a61d48d66dd458fa0b64990b6c8f8cc>:0 
11-27 18:54:44.469 E/mono    (29129):   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <3a61d48d66dd458fa0b64990b6c8f8cc>:0 
11-27 18:54:44.469 E/mono    (29129):   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <3a61d48d66dd458fa0b64990b6c8f8cc>:0 
11-27 18:54:44.469 E/mono    (29129):   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x0002b] in <3a61d48d66dd458fa0b64990b6c8f8cc>:0 
11-27 18:54:44.469 E/mono    (29129):   at System.Threading.ThreadHelper.ThreadStart () [0x00008] in <3a61d48d66dd458fa0b64990b6c8f8cc>:0 
bug-in-dependency

All 17 comments

Thanks for you detailed bug report. I will have to dig into this. It will take a few weeks before I get to this.

Similar problem was reported in SkiaSharp too.
https://github.com/mono/SkiaSharp/issues/793

Thanks a lot for the sample. I can reproduce it. Even is the Map object is not created at all. Not sure yet what is going on.

I did notice that the MapView is part of the ViewModel but it itself a UI component. In your sample it is removed from the main UI and then added back again. Perhaps it was not designed for this use.

I can also reproduce the problem if I use the forms MapControl instead of the MapView.

I hope I found reason - see https://github.com/mono/SkiaSharp/pull/1095

wow, nice!

I don't assume, that this solves the problem.

I assume it has the following reason: RefreshGraphics of MapControl repaints the control only, if SKGLView has a GRContext. If you move away from the page and come back, this isn't the case. It seems to be reassigned later. So, if you remove the check from this line, than you could refresh the graphics.

The above works, if you press zoom in or out or call RefreshGraphics() by hand, but not auomatically. For this, there should be an event, which is called, if the control is appearing on screen again. But I don't find such an event for Xamarin.Forms views.

I created a sample to reproduce the problem without Mapsui:
https://github.com/pauldendulk/mapsui-exception/tree/reproduce/without-mapsui

@charlenni Are you talking about the fix in skiasharp?

@pauldendulk Sorry, it's not my best day. The most of the above mentioned belongs to #746.

I will see what I can do to get a release out sooner for you folks. I'm queuing up a build for a preview release. As soon as that is out, you can have a test and see if everything is fixed.

@mattleibow ah great, I see you already merged it to master.

I just pushed out a preview (1.68.2-preview.17) to the preview feed so you can try it out now. I just want to do a few more checks and then it will go to nuget.org.

The preview feed is https://nugetized.blob.core.windows.net/skiasharp-eap/index.json

Great job, now it works like a charm ^_^ thanks a lot!

All was looking good, so I pushed out a preview to nuget.org. If there are any issues, just open a bug in the repo: https://www.nuget.org/packages/SkiaSharp/1.68.2-preview.17

You are awesome @mattleibow!

This afternoon 2.0.0-beta.32 was released with skiasharp 1.68.2-preview.17.

Since @jabools reports his problem is fixed I will close this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Wil69 picture Wil69  路  5Comments

charlenni picture charlenni  路  3Comments

kisslori picture kisslori  路  8Comments

lukaszpitulski picture lukaszpitulski  路  3Comments

lukaszpitulski picture lukaszpitulski  路  3Comments