Skiasharp: [BUG] macOS NullReferenceException when using SKGLView control

Created on 29 Mar 2019  路  10Comments  路  Source: mono/SkiaSharp

Description
The SKGLView control doesn't seem to work on macOS. It crashes with a NullReferenceException that narrows down to the platform SKGLView in the DrawRect method. I believe that when you just have a SKGLView control without painting anything on it it would crash.

Stacktrace:

at SkiaSharp.Views.Mac.SKGLView.DrawRect (CoreGraphics.CGRect dirtyRect) [0x000d0] in <f196d3fbe68d4774a19d9220fd09cf57>:0 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.16/src/Xamarin.Mac/AppKit/NSApplication.cs:100 at TestProject.Mac.MainClass.Main (System.String[] args) [0x00017] in /Users/localusr/Projects/TestProject/TestProject.Mac/Main.cs:11
Expected Behavior
The SKGLView should work and drawing on it should be supported.

Actual Behavior
The app crashes whenever you have a SKGLView control in your xamarin.forms app.

Basic Information

  • Version with issue: 1.68.0
  • Last known good version: unknown.
  • IDE: Visual Studio for Mac 7.8.3 (build 2)
  • Platform Target Frameworks:

    • macOS: macOS Mojave: 10.14.4
  • Target Devices:

    • Mac mini (Late 2014)

Reproduction Link

Here is a sample project:

TestProject.zip

type-duplicate

Most helpful comment

I just tested this in a blank project, here is a repro for the issue (Xamarin.Forms on macOS).
https://github.com/nor0x/SkiaSharp_PerfomanceExperiments/tree/master/Xamarin.Forms

Stacktrace

at SkiaSharp.Views.Mac.SKGLView.DrawRect (CoreGraphics.CGRect dirtyRect) [0x000d0] in <f196d3fbe68d4774a19d9220fd09cf57>:0
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.10.0.157/src/Xamarin.Mac/AppKit/NSApplication.cs:100 
at SkiaXFPlayground.macOS.MainClass.Main (System.String[] args) [0x00017] in /Users/johnny/SkiaPlayground/Xamarin.Forms/SkiaXFPlayground.macOS/Main.cs:11

Any updates on this one @mattleibow ?
Thanks

All 10 comments

After testing it on a macbook pro with a discrete video card it does work. The difference is that mac mini doesn't have a discrete video card.

I have the same issue on a MacBook Pro (13-inch, 2018, Four Thunderbolt 3 Ports)

I just tested this in a blank project, here is a repro for the issue (Xamarin.Forms on macOS).
https://github.com/nor0x/SkiaSharp_PerfomanceExperiments/tree/master/Xamarin.Forms

Stacktrace

at SkiaSharp.Views.Mac.SKGLView.DrawRect (CoreGraphics.CGRect dirtyRect) [0x000d0] in <f196d3fbe68d4774a19d9220fd09cf57>:0
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.10.0.157/src/Xamarin.Mac/AppKit/NSApplication.cs:100 
at SkiaXFPlayground.macOS.MainClass.Main (System.String[] args) [0x00017] in /Users/johnny/SkiaPlayground/Xamarin.Forms/SkiaXFPlayground.macOS/Main.cs:11

Any updates on this one @mattleibow ?
Thanks

@nor0x Does your MacBook Pro have a discrete videocard?

@aodpi no it doesn't. In the hardware infos the only entry is.
Intel Iris Plus Graphics 655 1536 MB graphics

@nor0x I took the code for SKGLView and created a new view and used it natively on macOS and it works with no issues, no crashes event on a mac with no dedicated gpu, so GPU is not the issue here 馃槥.

After some more digging, this line causes the issue:
https://github.com/mono/SkiaSharp/blob/5e8dc3e2c9e72f2ad0d9feecefbef503ca9fcc15/source/SkiaSharp.Views/SkiaSharp.Views.Mac/SKGLView.cs#L100

The SKSurface.Create method with the signature above returns null thus causing the NullReferenceException. I've also installed the early access build v1.68.1-rc.138 and it works well. Changes to SKSurface from the last release (v 1.68.0) seem to have fixed this issue.

Actually, changes in the mac SKGLView diff have fixed this issue. It's related to the way the surface samples count read.

Yep, it has been fixed here https://github.com/mono/SkiaSharp/issues/727#issuecomment-448425962 #727 . I think I will close this issue.

thanks for the response and closing, it鈥檚 great to see this fixed

Was this page helpful?
0 / 5 - 0 ratings