Description
i using SkiaSharp in a Xamarin.Forms app on macOS, after following the discussion in #1144 i have updated to the latest preview .45 which unfortunately doesn't solve the issue with native crashes for me (gr_backendrendertarget_get_gl_framebufferinfo). I have a different issue open which is related to SKImage #1164 but i'm not sure if this is the same - so here is a new open issue 🤓
I'm using an SKGLView to draw several shapes and images which lead to a freeze and the following native crash.
Code
in my case it might be related with GRContext.GetResourceCacheUsage 🤷♂️
=================================================================
Native Crash Reporting
=================================================================
Got a SIGSEGV 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:
=================================================================
0x107350d28 - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : mono_dump_native_crash_info
0x1073446e5 - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : mono_handle_native_crash
0x107661303 - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : altstack_handle_and_restore.cold.1
0x1072c1dac - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : altstack_handle_and_restore
0x107d34465 - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MonoBundle/libSkiaSharp.dylib : gr_backendrendertarget_get_gl_framebufferinfo
0x142ab5e43 - Unknown
0x142ab5c3b - Unknown
0x142ab4803 - Unknown
0x14294fec3 - Unknown
0x142949c63 - Unknown
0x142946c14 - Unknown
0x142946ae8 - Unknown
0x142944bed - Unknown
0x142943d6b - Unknown
0x142943f7e - Unknown
0x10735b1ee - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : mono_jit_runtime_invoke
0x10748d318 - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : mono_runtime_invoke_checked
0x107491c9e - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : mono_runtime_invoke
0x1072133d2 - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : xamarin_invoke_trampoline
0x10721499b - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : xamarin_arch_trampoline
0x107215bc6 - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : xamarin_x86_64_common_trampoline
0x7fff33acfe29 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSWindow(NSGestureRecognizer_Routing) _sendEventToGestureRecognizers:requireAcceptsFirstMouse:]
0x7fff33ad7ac2 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:]
0x7fff33a41c5c - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:]
0x7fff33a41005 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSWindow(NSEventRouting) sendEvent:]
0x7fff33a3f37c - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSApplication(NSEvent) sendEvent:]
0x7fff3388b0cf - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSApplication run]
0x7fff3385d465 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : NSApplicationMain
0x1113e8aec - Unknown
0x1112bc2a3 - Unknown
0x10879d8fb - Unknown
0x10879da91 - Unknown
0x10735b1ee - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : mono_jit_runtime_invoke
0x10748d318 - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : mono_runtime_invoke_checked
0x1074947c5 - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : mono_runtime_exec_main_checked
0x1072b7e9c - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : mono_jit_exec
0x1072bafd4 - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : mono_main
0x107216578 - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : xamarin_main
0x1072173e4 - /Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MacOS/Project : main
0x7fff6dd7a7fd - /usr/lib/system/libdyld.dylib : start
=================================================================
Telemetry Dumper:
=================================================================
Pkilling 0x70000a25d000 from 0x108a2edc0
Pkilling 0x70000e14f000 from 0x108a2edc0
Pkilling 0x70000a866000 from 0x108a2edc0
Pkilling 0x70000b587000 from 0x108a2edc0
Pkilling 0x70000e758000 from 0x108a2edc0
Pkilling 0x70000ae6f000 from 0x108a2edc0
Pkilling 0x70000bb90000 from 0x108a2edc0
Pkilling 0x70000ed61000 from 0x108a2edc0
Pkilling 0x70000c199000 from 0x108a2edc0
Pkilling 0x70000c7a2000 from 0x108a2edc0
Pkilling 0x70000d740000 from 0x108a2edc0
Pkilling 0x70000e352000 from 0x108a2edc0
Pkilling 0x70000aa69000 from 0x108a2edc0
Pkilling 0x70000b78a000 from 0x108a2edc0
Pkilling 0x70000e95b000 from 0x108a2edc0
Pkilling 0x70000b072000 from 0x108a2edc0
Pkilling 0x70000bd93000 from 0x108a2edc0
Pkilling 0x70000c39c000 from 0x108a2edc0
Pkilling 0x700009d51000 from 0x108a2edc0
Pkilling 0x70000c9a5000 from 0x108a2edc0
Pkilling 0x70000d943000 from 0x108a2edc0
Pkilling 0x70000df4c000 from 0x108a2edc0
Pkilling 0x70000a663000 from 0x108a2edc0
Pkilling 0x70000e555000 from 0x108a2edc0
Pkilling 0x70000ac6c000 from 0x108a2edc0
Pkilling 0x70000b98d000 from 0x108a2edc0
Pkilling 0x70000eb5e000 from 0x108a2edc0
Pkilling 0x70000b275000 from 0x108a2edc0
Pkilling 0x70000bf96000 from 0x108a2edc0
Pkilling 0x700009f54000 from 0x108a2edc0
Pkilling 0x70000cba8000 from 0x108a2edc0
Pkilling 0x70000d1b1000 from 0x108a2edc0
Could not exec mono-hang-watchdog, expected on path '/Users/Documents/Dev/Project/Project.MyProject.MacOS/bin/Debug/Project.app/Contents/MonoBundle/../bin/mono-hang-watchdog' (errno 2)
Entering thread summarizer pause from 0x108a2edc0
Finished thread summarizer pause from 0x108a2edc0.
Waiting for dumping threads to resume
=================================================================
External Debugger Dump:
=================================================================
socket_transport_send Cannot transition thread 0x108a2edc0 from STATE_BLOCKING with DO_BLOCKING
Expected Behavior
SKGLView should render without any problems+
Actual Behavior
random freezes and stuck app - only force close or killall lldb helps in my case
Basic Information
Platform Target Frameworks:
Target Devices:
Reproduction Link
With this crash, are you using the ToTextureImage? If so, does it still crash without it?
Also, are you running the updates to the SkiaSharp.Views package? That is where the bug was.
Finally, did you clean and rebuild? Sometimes the old assemblies are used. But I am assuming that you did and this is more for the native binaries. But, maybe straws need to be clutched earlier on? :)
i'm not using ToTextureImage in my current tests. i'm drawing some shapes (rectangles, polygons, circles,...) which can be dragged and scaled. i cannot share the project source with the public though.
SkiaSharp and SkiaSharp.Views are both on version 1.68.2-preview.45
I bet it is related to #1137 which is still the root cause of #1121. Something is being disposed incorrectly. And this happens with the GL bits which is usually with more threads. So, I am looking at that still. I worked around the main crash in #1180, but the underlying issue is still there. I believe I have a repro case as well.
thanks for your hard work. i'm happy to share more details and code in a private session because it's a big and closed source project i'm working on right now.
Awesome, thanks. Let me see what I can do with what I have right now and then if that doesn't work we can talk about your code.
I think I found the cause and fix of the issue. It was due to concurrency with the construction and destruction of objects with the same native handle. As soon as PR #1200 is complete, then I'll push to the preview feed for testing.
sounds great! thanks for the fix :-)
@nor0x I have pushed what I think is now a good version to the preview feed: https://aka.ms/skiasharp-eap/index.json
Check out the PR version: 1.68.2-pr.1200.20
Let me know how it goes.
Hey folks, it has been a long time coming and thanks to all the folks with your repros, samples and stack traces I think we have finally managed to fix those pesky crashes - at least the ones we know about. I have just pushed 1.68.2-preview.50 to NuGet so let me know if this fixes all the crashes you have ever had 😄
thanks for the preview build! works great for me 🎉
All good? Awesome!
Oh no, too early. In my first quick tests everything was fine, but now after more intense testing i'm experiencing random native crashes / freezes again. I really don't wanted to reopen this 🙈 @mattleibow
not sure if it helps, but if if i go back to preview .43 these crashes seems to happen less often 🤷♂️
=================================================================
Native Crash Reporting
=================================================================
Got a SIGSEGV 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:
=================================================================
0x10f31fbd8 - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : mono_dump_native_crash_info
0x10f313595 - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : mono_handle_native_crash
0x10f629023 - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : altstack_handle_and_restore.cold.1
0x10f290c5c - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : altstack_handle_and_restore
0x1102f7465 - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MonoBundle/libSkiaSharp.dylib : gr_backendrendertarget_get_gl_framebufferinfo
0x14e818c63 - Unknown
0x14e818a5b - Unknown
0x14e817563 - Unknown
0x14e80bc53 - Unknown
0x14e7f7c63 - Unknown
0x14e80aa44 - Unknown
0x14e80a918 - Unknown
0x14e80967d - Unknown
0x14e8087fb - Unknown
0x14e808a0e - Unknown
0x10f32a09e - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : mono_jit_runtime_invoke
0x10f45c1c8 - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : mono_runtime_invoke_checked
0x10f460b4e - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : mono_runtime_invoke
0x10f1e2397 - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : xamarin_invoke_trampoline
0x10f1e38e9 - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : xamarin_arch_trampoline
0x10f1e4aee - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : xamarin_x86_64_common_trampoline
0x7fff2e483574 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSWindow(NSGestureRecognizer_Routing) _sendEventToGestureRecognizers:requireAcceptsFirstMouse:]
0x7fff2e48b235 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:]
0x7fff2e3f5a81 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:]
0x7fff2e3f4e29 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSWindow(NSEventRouting) sendEvent:]
0x7fff2e3f31b4 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSApplication(NSEvent) sendEvent:]
0x7fff2e24021f - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSApplication run]
0x7fff2e211ff6 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : NSApplicationMain
0x119387cac - Unknown
0x1191d82a3 - Unknown
0x1100408fb - Unknown
0x110040a91 - Unknown
0x10f32a09e - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : mono_jit_runtime_invoke
0x10f45c1c8 - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : mono_runtime_invoke_checked
0x10f463675 - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : mono_runtime_exec_main_checked
0x10f286d4c - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : mono_jit_exec
0x10f289e84 - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : mono_main
0x10f1e547c - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : xamarin_main
0x10f1e62b4 - /MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MacOS/MyProject : main
0x7fff6af1acc9 - /usr/lib/system/libdyld.dylib : start
0x2 - Unknown
=================================================================
Telemetry Dumper:
=================================================================
Pkilling 0x700009e0f000 from 0x1101dedc0
Pkilling 0x70000e996000 from 0x1101dedc0
Pkilling 0x70000b742000 from 0x1101dedc0
Pkilling 0x70000bd4b000 from 0x1101dedc0
Pkilling 0x70000d375000 from 0x1101dedc0
Pkilling 0x70000c354000 from 0x1101dedc0
Pkilling 0x70000d97e000 from 0x1101dedc0
Pkilling 0x70000aa2a000 from 0x1101dedc0
Pkilling 0x70000c95d000 from 0x1101dedc0
Pkilling 0x70000df87000 from 0x1101dedc0
Pkilling 0x70000b033000 from 0x1101dedc0
Pkilling 0x70000e590000 from 0x1101dedc0
Pkilling 0x70000a012000 from 0x1101dedc0
Pkilling 0x70000eb99000 from 0x1101dedc0
Pkilling 0x70000b945000 from 0x1101dedc0
Pkilling 0x70000bf4e000 from 0x1101dedc0
Pkilling 0x70000d578000 from 0x1101dedc0
Pkilling 0x70000a624000 from 0x1101dedc0
Pkilling 0x70000c557000 from 0x1101dedc0
Pkilling 0x70000db81000 from 0x1101dedc0
Pkilling 0x70000a298000 from 0x1101dedc0
Pkilling 0x70000ac2d000 from 0x1101dedc0
Pkilling 0x70000cb60000 from 0x1101dedc0
Pkilling 0x70000e18a000 from 0x1101dedc0
Pkilling 0x70000b236000 from 0x1101dedc0
Pkilling 0x70000e793000 from 0x1101dedc0
Pkilling 0x70000b53f000 from 0x1101dedc0
Pkilling 0x70000bb48000 from 0x1101dedc0
Pkilling 0x70000d172000 from 0x1101dedc0
Pkilling 0x70000c151000 from 0x1101dedc0
Pkilling 0x70000d77b000 from 0x1101dedc0
Pkilling 0x70000a827000 from 0x1101dedc0
Pkilling 0x70000c75a000 from 0x1101dedc0
Pkilling 0x70000dd84000 from 0x1101dedc0
Pkilling 0x70000cd63000 from 0x1101dedc0
Pkilling 0x70000ae30000 from 0x1101dedc0
Pkilling 0x70000e38d000 from 0x1101dedc0
Could not exec mono-hang-watchdog, expected on path '/MyPath/MyProject/MyProject.MacOS/bin/Debug/MyProject.app/Contents/MonoBundle/../bin/mono-hang-watchdog' (errno 2)
Entering thread summarizer pause from 0x1101dedc0
Finished thread summarizer pause from 0x1101dedc0.
Waiting for dumping threads to resume
socket_transport_send Cannot transition thread 0x1101dedc0 from STATE_BLOCKING with DO_BLOCKING
=================================================================
External Debugger Dump:
=================================================================
At this point I don't think this is the concurrency anymore. It may be that the GC is collection things that are no longer used on the managed side.
This is gonna be crazy, but try using a GC.KeepAlive(<object>) for all skia objects. Or add them to a "method global" list:
void OnPaint() {
var paint = new SKPaint();
...
GC.KeepAlive(paint);
}
void OnPaint() {
var objects = new List<SKObject>();
var paint = new SKPaint();
objects.Add(paint);
...
}
Basically, you want to keep these objects alive as long as possible.
But, if this is gonna be to crazy to do on your codebase, then we can talk over a private connection and maybe I can have a look at the drawing code. Maybe something will pop out.
My email is [email protected], just drop me an email and we can talk.
alright i have added try the KeepAlive suggestion and i have dropped you an email since my drawing code is somewhat complex. Thanks @mattleibow
seems to be fixed by #1224. after a lot of testing i don't get any crashes so i'm closing this now, hopefully for good