SkiaSharp: NullReferenceException in System.Delegate.Combine on macOS in 1.68.0
Description
After updating from 1.60.3
to 1.68.0
. I’m getting a NullReferenceException
when I try to subscribe to the PaintSurface
event of a SKGLView
.
Code
NullReferenceException" at System.Delegate.Combine (System.Delegate a, System.Delegate b) [0x0001d] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.2.1.12/src/Xamarin.Mac/mcs/class/corlib/System/Delegate.cs:548
at SkiaSharp.Views.Mac.SKGLView.add_PaintSurface (System.EventHandler1[TEventArgs] value) [0x00009] in <f196d3fbe68d4774a19d9220fd09cf57>:0
at MyViewController+<ViewDidLoad>d__59.MoveNext () [0x00277] in -mypath-MyViewController.cs:599
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.2.1.12/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1023
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00002] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.2.1.12/src/Xamarin.Mac/Foundation/NSAction.cs:178
at (wrapper managed-to-native) AppKit.NSApplication.NSApplicationMain(int,string[])
at AppKit.NSApplication.Main (System.String[] args) [0x00040] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.2.1.12/src/Xamarin.Mac/AppKit/NSApplication.cs:100
at MainClass.Main (System.String[] args) [0x00007] in main.cs:10
Expected Behavior
The NullReferenceException above is thrown once I subscribe to the PaintSurface
event of SKGLView
in a NSViewController
.
CanvasView.PaintSurface += CanvasView_PaintSurface;
I haven’t changed any code, just updated the NuGet package for SkiaSharp
and SkiaSharp.Views
from 1.60.3
to 1.68.0
.
Basic Information
-
Version with issue: 1.68.0
-
Last known good version: 1.60.3
-
IDE: Visual Studio for Mac 7.7.1 (build 15)
-
Platform Target Frameworks:
- macOS: 10.14.1
-
Target Devices:
- MacBook Pro (13-inch, 2018)
VS bug #754181
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 27 (15 by maintainers)
I believe I fixed the issue by not assuming what my samples are, but rather asking the system. I updated the way surface are created in ALL the views as well, just to prevent any future issue on other platforms. https://github.com/mono/SkiaSharp/pull/741
OK, I think I know what to do now. I can query the context for the supported sample count. In the meantime, you can use SKCanvasView or the custom view.
I am going to improve the views a bit since they haven’t really been touched since the beginning. I need to add colorspace support as well, see #732
All right, I have found the issue. It appears that on my old MacBook, I can only have a surface with 1 sample. And, on my new MacBook, I can have 8. In both cases, I requested 4, but appears that I only got 1 on one machine and 8 on another.
I need to investigate this some more, but I can implement a fix for the time being - I can just query SkiaSharp for the number of samples that it is allowed.
In the meantime, you can see what your machine outputs but running this modified app:
Source: Modified.zip App: SkiaSharpMacTest.app.zip
Let me know what you get on your side before I make any changes…
One last thing to check is to send me your .app file and I can run it here to confirm that it is your system - it might be just the tooling used to build the package is bad and affecting the running. I have also contacted our resident mac experts to get some real advice.
The only thing that I can see as a difference is the OS:
ME Mac OS X 10.13.6 Darwin 17.7.0 Darwin Kernel Version 17.7.0 Fri Nov 2 20:43:16 PDT 2018 root:xnu-4570.71.17~1/RELEASE_X86_64 x86_64
YOU Mac OS X 10.14.2 Darwin 18.2.0 Darwin Kernel Version 18.2.0 Mon Nov 12 20:24:46 PST 2018 root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64
It appears my mac did not actually let me know there was a major update 😭 I’ll update and see what happens.
clearing the nuget cache or deleting the skiasharp packages manually didn’t solve the problem. I will run the code on a second mac tomorrow. Here are the details from VS > About
I’m using Xamarin.Mac not Xamarin.Forms.
attaching
CanvasView_PaintSurface
to a dummy SKGLView object works fine. I will look into my initialization method tomorrow and check what I can share. I’m happy to send you some source files via email. Thank you