Open ylatuya opened 3 years ago
I have found a workaround for the issue which is forcing the disposal of objects in the. window destruction: https://github.com/ylatuya/OpenTKSkiaGtk2/commit/92914af5b298764513d20f5a78c2999c67298b80
It looks like if objects are not disposed and the dispose code is called in the finalizers, it's too late. This is probably because the graphics context is already disposed at that moment.
Description
In macOS using the GL backend, the SKSurface finalizer causes a segfault in the native code. I am able to reproduce the issue consistently on every run with the following sample application https://github.com/ylatuya/OpenTKSkiaGtk2
Stacktrace
``` Loaded assembly: /Users/andoni/Projects/OpenTKSkia/OpenTKSkiaGtk2/bin/Debug/OpenTKSkia.exe Loaded assembly: /Users/andoni/Projects/OpenTKSkia/OpenTKSkiaGtk2/bin/Debug/SkiaSharp.dll [External] Loaded assembly: /Users/andoni/Projects/OpenTKSkia/OpenTKSkiaGtk2/bin/Debug/OpenTK.dll [External] Loaded assembly: /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/gac/gtk-sharp/2.12.0.0__35e10195dab3c99f/gtk-sharp.dll [External] Loaded assembly: /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/gac/glib-sharp/2.12.0.0__35e10195dab3c99f/glib-sharp.dll [External] Loaded assembly: /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/gac/atk-sharp/2.12.0.0__35e10195dab3c99f/atk-sharp.dll [External] Loaded assembly: /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll [External] Loaded assembly: /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/gac/gdk-sharp/2.12.0.0__35e10195dab3c99f/gdk-sharp.dll [External] Loaded assembly: /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/gac/Mono.Posix/4.0.0.0__0738eb9f132ed756/Mono.Posix.dll [External] (OpenTKSkia:46523): Gtk-WARNING **: Locale not supported by C library. Using the fallback 'C' locale. OpenTK running on OSX Loaded assembly: /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll [External] Loaded assembly: Anonymously Hosted DynamicMethods Assembly [External] Loaded assembly: /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/4.5/Facades/System.Runtime.InteropServices.RuntimeInformation.dll [External] ================================================================= Native Crash Reporting ================================================================= Got a segv while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application. ================================================================= ================================================================= Native stacktrace: ================================================================= 0x10028a779 - /Library/Frameworks/Mono.framework/Versions/6.12.0/bin/mono64 : mono_dump_native_crash_info 0x1002225be - /Library/Frameworks/Mono.framework/Versions/6.12.0/bin/mono64 : mono_handle_native_crash 0x1002848f8 - /Library/Frameworks/Mono.framework/Versions/6.12.0/bin/mono64 : altstack_handle_and_restore 0x7fff3764f8ac - /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib : glDeleteBuffers 0x109d83f1c - /Users/andoni/Projects/OpenTKSkia/OpenTKSkiaGtk2/bin/Debug/libSkiaSharp.dylib : gr_backendrendertarget_get_gl_framebufferinfo 0x109c27a8f - /Users/andoni/Projects/OpenTKSkia/OpenTKSkiaGtk2/bin/Debug/libSkiaSharp.dylib : gr_backendrendertarget_get_gl_framebufferinfo 0x109c4f2fa - /Users/andoni/Projects/OpenTKSkia/OpenTKSkiaGtk2/bin/Debug/libSkiaSharp.dylib : gr_backendrendertarget_get_gl_framebufferinfo 0x109c32e1b - /Users/andoni/Projects/OpenTKSkia/OpenTKSkiaGtk2/bin/Debug/libSkiaSharp.dylib : gr_backendrendertarget_get_gl_framebufferinfo 0x109c4d976 - /Users/andoni/Projects/OpenTKSkia/OpenTKSkiaGtk2/bin/Debug/libSkiaSharp.dylib : gr_backendrendertarget_get_gl_framebufferinfo 0x109c1cdb9 - /Users/andoni/Projects/OpenTKSkia/OpenTKSkiaGtk2/bin/Debug/libSkiaSharp.dylib : gr_backendrendertarget_get_gl_framebufferinfo 0x109c291eb - /Users/andoni/Projects/OpenTKSkia/OpenTKSkiaGtk2/bin/Debug/libSkiaSharp.dylib : gr_backendrendertarget_get_gl_framebufferinfo 0x109d03688 - /Users/andoni/Projects/OpenTKSkia/OpenTKSkiaGtk2/bin/Debug/libSkiaSharp.dylib : gr_backendrendertarget_get_gl_framebufferinfo 0x109a022af - /Users/andoni/Projects/OpenTKSkia/OpenTKSkiaGtk2/bin/Debug/libSkiaSharp.dylib : gr_backendrendertarget_get_gl_framebufferinfo 0x109a01e95 - /Users/andoni/Projects/OpenTKSkia/OpenTKSkiaGtk2/bin/Debug/libSkiaSharp.dylib : gr_backendrendertarget_get_gl_framebufferinfo 0x109a022ee - /Users/andoni/Projects/OpenTKSkia/OpenTKSkiaGtk2/bin/Debug/libSkiaSharp.dylib : gr_backendrendertarget_get_gl_framebufferinfo 0x109d0e550 - /Users/andoni/Projects/OpenTKSkia/OpenTKSkiaGtk2/bin/Debug/libSkiaSharp.dylib : gr_backendrendertarget_get_gl_framebufferinfo 0x10a31ba8c - Unknown 0x10a31b945 - Unknown 0x10a31b7ab - Unknown 0x10a31b583 - Unknown 0x10a31a29a - Unknown 0x10a31a01b - Unknown 0x10a3240cb - Unknown 0x10a319d6f - Unknown 0x10a319b82 - Unknown 0x1003f9939 - /Library/Frameworks/Mono.framework/Versions/6.12.0/bin/mono64 : mono_gc_run_finalize 0x100418a6c - /Library/Frameworks/Mono.framework/Versions/6.12.0/bin/mono64 : sgen_gc_invoke_finalizers 0x1003fb829 - /Library/Frameworks/Mono.framework/Versions/6.12.0/bin/mono64 : finalizer_thread 0x1003b9d3d - /Library/Frameworks/Mono.framework/Versions/6.12.0/bin/mono64 : start_wrapper 0x7fff679cd109 - /usr/lib/system/libsystem_pthread.dylib : _pthread_start 0x7fff679c8b8b - /usr/lib/system/libsystem_pthread.dylib : thread_start ================================================================= Telemetry Dumper: ================================================================= Pkilling 0x4429610432x from 0x123145405673472x Pkilling 0x123145407782912x from 0x123145405673472x Entering thread summarizer pause from 0x123145405673472x Finished thread summarizer pause from 0x123145405673472x. Failed to create breadcrumb file (null)/crash_hash_0xef678eeec Waiting for dumping threads to resume ================================================================= External Debugger Dump: ================================================================= ================================================================= Basic Fault Address Reporting ================================================================= Memory around native instruction pointer (0x7fff3764f8ac):0x7fff3764f89c 89 e5 48 89 f2 89 fe 65 48 8b 04 25 f0 00 00 00 ..H....eH..%.... 0x7fff3764f8ac 48 8b 88 20 14 00 00 48 8b 38 5d ff e1 55 48 89 H.. ...H.8]..UH. 0x7fff3764f8bc e5 48 89 f2 89 fe 65 48 8b 04 25 f0 00 00 00 48 .H....eH..%....H 0x7fff3764f8cc 8b 88 28 14 00 00 48 8b 38 5d ff e1 55 48 89 e5 ..(...H.8]..UH.. ================================================================= Managed Stacktrace: ================================================================= atCode
Expected Behavior
The application is closed correctly, finalizers are run and no segfault happen
Actual Behavior
There is a native segfault calling the finalizers
Basic Information
Screenshots
Reproduction Link
https://github.com/ylatuya/OpenTKSkiaGtk2