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)

Commits related to this issue

Most upvoted comments

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

=== Visual Studio Professional 2017 for Mac ===

Version 7.7.2 (build 21)
Installation UUID: 606b8730-5344-4f22-8895-9af524c45723
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)

	Package version: 516000221

=== Mono Framework MDK ===

Runtime:
	Mono 5.16.0.221 (2018-06/b63e5378e38) (64-bit)
	Package version: 516000221

=== NuGet ===

Version: 4.8.0.5385

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	2.2.0
	2.1.5
	2.1.2
SDK: /usr/local/share/dotnet/sdk/2.2.100/Sdks
SDK Versions:
	2.2.100
	2.1.403
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.4
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 10.1 (14460.46)
Build 10B61

=== Xamarin.Mac ===

Version: 5.2.1.12 (Visual Studio Professional)
Hash: 65ec520f
Branch: 
Build date: 2018-12-05 12:06:09-0500

=== Xamarin.iOS ===

Version: 12.2.1.12 (Visual Studio Professional)
Hash: 65ec520f
Branch: d15-9
Build date: 2018-12-05 12:06:09-0500

=== Xamarin.Android ===

Version: 9.1.4.2 (Visual Studio Professional)
Android SDK: /Users/johnny/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		7.0 (API level 24)
		7.1 (API level 25)
		8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.1
SDK Build Tools Version: 27.0.3

Java SDK: /Users/johnny/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.9
openjdk version "1.8.0-9"
OpenJDK Runtime Environment (build 1.8.0-9-microsoft-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android Device Manager ===

Version: 7.7.1.0
Hash: 06ceaea1

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 707020021
Git revision: f1fea53df9eb0bb5890a9563c0d7ea7b03922144
Build date: 2018-12-14 18:37:35+00
Build branch: release-7.7
Xamarin extensions: 9c5cea335e6a9ce4ccfde31c4aa06c25a3576085

=== Operating System ===

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

=== Enabled user installed extensions ===

Prism Template Studio and Developer Toolkit 2.2.0.434


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