SkiaSharp.SKObject.Dispose can throw ArgumentNullException on finalization
See original GitHub issueHad 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:
- Created 5 years ago
- Comments:5 (3 by maintainers)
I encountered the same issue on Debian when libSkiaSharp.so was absent.
@davkean Thanks for your info and research. I fixed this issue and it is now in master.