question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SkiaSharp.SKObject.Dispose can throw ArgumentNullException on finalization

See original GitHub issue

Had a customer complaining about crashes in Visual Studio while using SkiaSharp in the WinForms designer: https://developercommunity.visualstudio.com/content/problem/228761/crashing-when-debugging-a-skiasharp-winforms-app-i.html.

Looking into his crashes it looks like SkiaSharp.SKObject.Dispose can throw on finalization:

   at System.Threading.Monitor.ReliableEnter(System.Object, Boolean ByRef)
   at SkiaSharp.SKObject.Dispose(Boolean)
   at SkiaSharp.SKPaint.Dispose(Boolean)
   at SkiaSharp.SKNativeObject.Finalize()

If you look at Dispose, you can see multiple paths where it attempts to access managed instance and static fields that have no guarantee about already being cleaned up by the time the finalizer has run: https://github.com/mono/SkiaSharp/blob/9a0bff839b2a951334252a18f94cb7367c06c5de/binding/Binding/SKObject.cs#L63

Any access to member/static reference fields should be guarded with if (disposing). Or Better yet, wrap the unmanaged handle in a SafeHandle and let it free it.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
aktzbncommented, Apr 12, 2018

I encountered the same issue on Debian when libSkiaSharp.so was absent.

0reactions
mattleibowcommented, Apr 13, 2018

@davkean Thanks for your info and research. I fixed this issue and it is now in master.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SKObject Class (SkiaSharp)
Gets or sets a value indicating whether this object owns it's handle and should destroy the native object when is is disposed.
Read more >
c# - Throwing ArgumentNullException
I prefer the ArgumentNullException over the NullReferenceException that not checking the argument would provide. In general, my preference ...
Read more >
Class BiffRecordRawWithArray - Documentation - Syncfusion
This is required when the real record size is not known for an Infill operation. Will throw exception on buffer offset overrun when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found