Description
Problem:
While most of the SkiaSharp objects can be safely disposed from any thread, GPU bound ones need the corresponding GPU context to be active on disposing thread. It's fine as long as the object lifetime is controlled by application, but Dispose might be called from the finalizer thread in following cases:
Main
has exitedEnvironment.Exit(...)
is called- Object was somehow leaked and collected by GC without being properly disposed
Libraries using SkiaSharp can deal with the third one by thoroughly controlling the object lifetimes, but unfortunately have no control over the application control flow. That leads to crashes such as AvaloniaUI/Avalonia#4423
Proposed solution:
Instead of calling Dispose
directly, call a user-specified callback that could properly enqueue the object for disposal on a proper thread or make the GPU context to be current. Such callback should be specified on object creation, e. g.
public static SKSurface Create (GRContext context, bool budgeted, SKImageInfo info, Action<Action> disposeCallback)
Finalizer should do something like this:
~SKSurface()
{
if(_disposeCallback != null)
_disposeCallback(() => Dispose(false));
else
Dispose(false);
}
Metadata
Metadata
Assignees
Type
Projects
Status