Native blob disposal from finalizer thread
See original GitHub issueDescribe the bug
Native blob disposal from finalizer thread
Backtrace: at System.Environment.get_StackTrace()
at Avalonia.Platform.Internal.UnmanagedBlob.Dispose() in /home/spaccabit/GitHub/Avalonia/src/Avalonia.Base/Platform/Internal/UnmanagedBlob.cs:line 87
at Avalonia.Skia.WriteableBitmapImpl.ReleaseProc(IntPtr address, Object ctx) in /home/spaccabit/GitHub/Avalonia/src/Skia/Avalonia.Skia/WriteableBitmapImpl.cs:line 177
at SkiaSharp.SKBitmap.<>c__DisplayClass108_0.<InstallPixels>b__0(IntPtr addr, Object _)
at SkiaSharp.DelegateProxies.SKBitmapReleaseDelegateProxyImplementation(Void* address, Void* context)
at SkiaSharp.SkiaApi.sk_bitmap_destructor(IntPtr cbitmap)
at SkiaSharp.SkiaApi.sk_bitmap_destructor(IntPtr cbitmap)
at SkiaSharp.SKBitmap.DisposeNative()
at SkiaSharp.SKNativeObject.Dispose(Boolean disposing)
at SkiaSharp.SKBitmap.Dispose(Boolean disposing)
at SkiaSharp.SKNativeObject.Finalize()
Blob created by at System.Environment.get_StackTrace()
at Avalonia.Platform.Internal.UnmanagedBlob..ctor(Int32 size) in /home/spaccabit/GitHub/Avalonia/src/Avalonia.Base/Platform/Internal/UnmanagedBlob.cs:line 53
at Avalonia.Platform.StandardRuntimePlatform.AllocBlob(Int32 size) in /home/spaccabit/GitHub/Avalonia/src/Avalonia.Base/Platform/StandardRuntimePlatform.cs:line 15
at Avalonia.Skia.WriteableBitmapImpl..ctor(PixelSize size, Vector dpi, PixelFormat format, AlphaFormat alphaFormat) in /home/spaccabit/GitHub/Avalonia/src/Skia/Avalonia.Skia/WriteableBitmapImpl.cs:line 107
at Avalonia.Skia.PlatformRenderInterface.CreateWriteableBitmap(PixelSize size, Vector dpi, PixelFormat format, AlphaFormat alphaFormat) in /home/spaccabit/GitHub/Avalonia/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs:line 228
at Avalonia.Media.Imaging.WriteableBitmap.CreatePlatformImpl(PixelSize size, Vector& dpi, Nullable`1 format, Nullable`1 alphaFormat) in /home/spaccabit/GitHub/Avalonia/src/Avalonia.Base/Media/Imaging/WriteableBitmap.cs:line 77
at Avalonia.Media.Imaging.WriteableBitmap..ctor(PixelSize size, Vector dpi, Nullable`1 format, Nullable`1 alphaFormat) in /home/spaccabit/GitHub/Avalonia/src/Avalonia.Base/Media/Imaging/WriteableBitmap.cs:line 22
at Avalonia.Controls.Primitives.ColorPickerHelpers.CreateBitmapFromPixelData(IList`1 bgraPixelData, Int32 pixelWidth, Int32 pixelHeight) in /home/spaccabit/GitHub/Avalonia/src/Avalonia.Controls.ColorPicker/Helpers/ColorPickerHelpers.cs:line 614
at Avalonia.Controls.Primitives.ColorSlider.UpdateBackground() in /home/spaccabit/GitHub/Avalonia/src/Avalonia.Controls.ColorPicker/ColorSlider/ColorSlider.cs:line 113
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecutionContextCallback(Object s)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext()
at System.Threading.Tasks.AwaitTaskContinuation.<>c.<.cctor>b__17_0(Object state)
at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(ContextCallback callback, Object state, Task& currentTask)
at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run(Task task, Boolean canInlineContinuationTask)
at System.Threading.Tasks.Task.RunContinuations(Object continuationObject)
at System.Threading.Tasks.Task`1.TrySetResult(TResult result)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetExistingTaskResult(Task`1 task, TResult result)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetResult(TResult result)
at Avalonia.Controls.Primitives.ColorPickerHelpers.CreateComponentBitmapAsync(Int32 width, Int32 height, Orientation orientation, ColorModel colorModel, ColorComponent component, HsvColor baseHsvColor, Boolean isAlphaMaxForced, Boolean isSaturationValueMaxForced) in /home/spaccabit/GitHub/Avalonia/src/Avalonia.Controls.ColorPicker/Helpers/ColorPickerHelpers.cs:line 307
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecutionContextCallback(Object s)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext()
at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.<>c.<.cctor>b__8_0(Object state)
at Avalonia.Threading.JobRunner.JobWithArg.Avalonia.Threading.JobRunner.IJob.Run() in /home/spaccabit/GitHub/Avalonia/src/Avalonia.Base/Threading/JobRunner.cs:line 241
at Avalonia.Threading.JobRunner.RunJobs(Nullable`1 priority) in /home/spaccabit/GitHub/Avalonia/src/Avalonia.Base/Threading/JobRunner.cs:line 38
at Avalonia.Controls.Platform.InternalPlatformThreadingInterface.RunLoop(CancellationToken cancellationToken) in /home/spaccabit/GitHub/Avalonia/src/Avalonia.Controls/Platform/InternalPlatformThreadingInterface.cs:line 27
at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken) in /home/spaccabit/GitHub/Avalonia/src/Avalonia.Base/Threading/Dispatcher.cs:line 61
at Avalonia.Controls.DesktopApplicationExtensions.Run(Application app, CancellationToken token) in /home/spaccabit/GitHub/Avalonia/src/Avalonia.Controls/DesktopApplicationExtensions.cs:line 55
at LinuxFramebufferPlatformExtensions.StartLinuxDirect[T](T builder, String[] args, IOutputBackend outputBackend, IInputBackend inputBackend) in /home/spaccabit/GitHub/Avalonia/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs:line 162
at LinuxFramebufferPlatformExtensions.StartLinuxFbDev[T](T builder, String[] args, String fbdev, Double scaling, IInputBackend inputBackend) in /home/spaccabit/GitHub/Avalonia/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs:line 146
at ControlCatalog.NetCore.Program.Main(String[] args) in /home/spaccabit/GitHub/Avalonia/samples/ControlCatalog.NetCore/Program.cs:line 47
Native blob disposal from finalizer thread
Backtrace: at System.Environment.get_StackTrace()
at Avalonia.Platform.Internal.UnmanagedBlob.Dispose() in /home/spaccabit/GitHub/Avalonia/src/Avalonia.Base/Platform/Internal/UnmanagedBlob.cs:line 87
at Avalonia.Skia.WriteableBitmapImpl.ReleaseProc(IntPtr address, Object ctx) in /home/spaccabit/GitHub/Avalonia/src/Skia/Avalonia.Skia/WriteableBitmapImpl.cs:line 177
at SkiaSharp.SKBitmap.<>c__DisplayClass108_0.<InstallPixels>b__0(IntPtr addr, Object _)
at SkiaSharp.DelegateProxies.SKBitmapReleaseDelegateProxyImplementation(Void* address, Void* context)
at SkiaSharp.SkiaApi.sk_bitmap_destructor(IntPtr cbitmap)
at SkiaSharp.SkiaApi.sk_bitmap_destructor(IntPtr cbitmap)
at SkiaSharp.SKBitmap.DisposeNative()
at SkiaSharp.SKNativeObject.Dispose(Boolean disposing)
at SkiaSharp.SKBitmap.Dispose(Boolean disposing)
at SkiaSharp.SKNativeObject.Finalize()
To Reproduce Steps to reproduce the behavior:
- Build Avalonia
- Go to Linux Terminal
- Go to samples/ControlCatalog.NetCore/bin/Debug/net6.0
- Write
dotnet ControlCatalog.NetCore.dll
- Go ColorPicker example
- See error in console
Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: Linux Ubuntu 22.04.1 64bit
- Version: 84791dbf2e772cad889d575ef64000b5ba3d637a
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created a year ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Native blob disposal from finalizer thread error when resizing ...
I get this errors when I resize window of ControlCatalog.NetCore using latest master.
Read more >Should Java finalizer really be avoided also for native peer ...
Generally, finalizers are considered a fallback option to invoke dispose() (or whatever) if the managing code fails to do so--and often printing ...
Read more >Why disposing NativeArray in a finalizer is unacceptable?
I have an idea to put all the NativeArray.Dispose() in the class's finalizer (~YourClass()) this way I would not have to propagate `IDisposable` ......
Read more >Disposing of vertex and index buffers causing context ...
I have double checked that my code is calling the vertex buffers dispose method on the same thread as the main game loop....
Read more >Scene Class - Typedescriptor
Dispose() sealed; FindNode(IVisual) Tries to find a node in the scene graph ... Native blob disposal from finalizer thread error when resizing window...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve been very uncomfortable with WritableBitmap usage in Avalonia as discussed in the first PR.
https://github.com/AvaloniaUI/Avalonia/blob/84791dbf2e772cad889d575ef64000b5ba3d637a/src/Avalonia.Controls.ColorPicker/Helpers/ColorPickerHelpers.cs#L620-L624
WritableBitmaps should be abstracted more for a managed environment IMO and not treated like native code. I wasn’t even aware disposal of these was necessary… probably should have been though. We definitely need more docs on this.
Anyway, I’ll fix disposal using the current WritableBitmap design along with a few other things in the next ColorPicker PR.
fixed in master 7dd09cd2a5e85bd006265a5a4e6a2c39b087c4e8