Bug 37536 - Crash with repeated calls to CGContext.DrawImage on actual iPad
Summary: Crash with repeated calls to CGContext.DrawImage on actual iPad
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2016-01-08 22:39 UTC by bobme981
Modified: 2016-01-15 04:10 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
repro solution (1.10 MB, application/x-zip-compressed)
2016-01-08 22:39 UTC, bobme981
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description bobme981 2016-01-08 22:39:24 UTC
Created attachment 14509 [details]
repro solution

See attached repro solution.

This is a simple app that displays a custom animation control. The control loops through 70 different pre-loaded CGImages (one every 20 ms) and draws them using CGContext.DrawImage.

There are two possibly related problems occurring, both of which occur ONLY when the app is run on an actual iPad, and not in the simulator:

1. Around 80% of the images are not rendered on the screen at all, even though the DrawImage call succeeds.

2. The app usually crashes almost immediately inside DrawImage, usually within the first 30 or so calls. It does not always crash on the same image. It is more likely to crash when the debugger is NOT attached.

Environment:
Simulator: iPad 2, iOS 9.2
Device: iPad 4, iOS 9.2

Stack trace:
2016-01-08 14:39:07.315 HelloWorld.iOS[1060:485332] critical: Stacktrace:
2016-01-08 14:39:07.316 HelloWorld.iOS[1060:485332] critical:   at <unknown> <0xffffffff>
2016-01-08 14:39:07.316 HelloWorld.iOS[1060:485332] critical:   at (wrapper managed-to-native) CoreGraphics.CGContext.CGContextDrawImage (intptr,CoreGraphics.CGRect,intptr) <0xffffffff>
2016-01-08 14:39:07.316 HelloWorld.iOS[1060:485332] critical:   at CoreGraphics.CGContext.DrawImage (CoreGraphics.CGRect,CoreGraphics.CGImage) [0x00000] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/CoreGraphics/CGContext.cs:822
2016-01-08 14:39:07.317 HelloWorld.iOS[1060:485332] critical:   at NGraphics.CGContextCanvas.DrawImage (NGraphics.IImage,NGraphics.Rect,double) [0x00074] in /Users/fak/Dropbox/Projects/NGraphics/Platforms/NGraphics.Mac/ApplePlatform.cs:452
2016-01-08 14:39:07.317 HelloWorld.iOS[1060:485332] critical:   at HelloWorld.iOS.GlobeView.Draw (NGraphics.ICanvas,NGraphics.Rect) [0x00099] in /Users/neoscoob/HelloWorld/iOS/GlobeView.cs:70
2016-01-08 14:39:07.317 HelloWorld.iOS[1060:485332] critical:   at NControl.iOS.NControlViewRenderer.Draw (CoreGraphics.CGRect) <IL 0x00065, 0x004c3>
2016-01-08 14:39:07.317 HelloWorld.iOS[1060:485332] critical:   at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>
2016-01-08 14:39:07.318 HelloWorld.iOS[1060:485332] critical:   at <unknown> <0xffffffff>
2016-01-08 14:39:07.318 HelloWorld.iOS[1060:485332] critical:   at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <0xffffffff>
2016-01-08 14:39:07.318 HelloWorld.iOS[1060:485332] critical:   at UIKit.UIApplication.Main (string[],intptr,intptr) [0x00005] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/UIKit/UIApplication.cs:77
2016-01-08 14:39:07.319 HelloWorld.iOS[1060:485332] critical:   at UIKit.UIApplication.Main (string[],string,string) [0x0001c] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/UIKit/UIApplication.cs:60
2016-01-08 14:39:07.319 HelloWorld.iOS[1060:485332] critical:   at HelloWorld.iOS.Application.Main (string[]) [0x00008] in /Users/neoscoob/HelloWorld/iOS/Main.cs:17
2016-01-08 14:39:07.319 HelloWorld.iOS[1060:485332] critical:   at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>
2016-01-08 14:39:07.319 HelloWorld.iOS[1060:485332] critical: 
Native stacktrace:

2016-01-08 14:39:07.968 HelloWorld.iOS[1060:485332] critical: 0   HelloWorld.iOS                      0x025b99e5 mono_handle_native_sigsegv + 240
2016-01-08 14:39:07.968 HelloWorld.iOS[1060:485332] critical: 1   HelloWorld.iOS                      0x025bfc63 mono_sigsegv_signal_handler + 226
2016-01-08 14:39:07.969 HelloWorld.iOS[1060:485332] critical: 2   libsystem_platform.dylib            0x2589785f _sigtramp + 42
2016-01-08 14:39:07.969 HelloWorld.iOS[1060:485332] critical: 3   CoreFoundation                      0x25a9ab17 CFDataGetBytes + 130
2016-01-08 14:39:07.969 HelloWorld.iOS[1060:485332] critical: 4   CoreFoundation                      0x25a9ab17 CFDataGetBytes + 130
2016-01-08 14:39:07.969 HelloWorld.iOS[1060:485332] critical: 5   ImageIO                             0x26f18bd7 <redacted> + 550
2016-01-08 14:39:07.970 HelloWorld.iOS[1060:485332] critical: 6   ImageIO                             0x26f189a5 CGImageReadSessionGetBytes + 24
2016-01-08 14:39:07.970 HelloWorld.iOS[1060:485332] critical: 7   ImageIO                             0x270a3ecb <redacted> + 22
2016-01-08 14:39:07.970 HelloWorld.iOS[1060:485332] critical: 8   ImageIO                             0x26f188f9 <redacted> + 44
2016-01-08 14:39:07.970 HelloWorld.iOS[1060:485332] critical: 9   ImageIO                             0x26f1852d <redacted> + 32
2016-01-08 14:39:07.971 HelloWorld.iOS[1060:485332] critical: 10  ImageIO                             0x26f219e1 <redacted> + 1812
2016-01-08 14:39:07.971 HelloWorld.iOS[1060:485332] critical: 11  ImageIO                             0x26f20a31 <redacted> + 820
2016-01-08 14:39:07.971 HelloWorld.iOS[1060:485332] critical: 12  CoreGraphics                        0x26bc4683 CGImageProviderCopyImageBlockSetWithOptions + 162
2016-01-08 14:39:07.971 HelloWorld.iOS[1060:485332] critical: 13  CoreGraphics                        0x26bc4339 <redacted> + 356
2016-01-08 14:39:07.972 HelloWorld.iOS[1060:485332] critical: 14  CoreGraphics                        0x26bb72f5 <redacted> + 1316
2016-01-08 14:39:07.972 HelloWorld.iOS[1060:485332] critical: 15  CoreGraphics                        0x26bb6583 CGSImageDataLock + 94
2016-01-08 14:39:07.972 HelloWorld.iOS[1060:485332] critical: 16  libRIP.A.dylib                      0x35126fc7 <redacted> + 634
2016-01-08 14:39:07.973 HelloWorld.iOS[1060:485332] critical: 17  libRIP.A.dylib                      0x35126083 <redacted> + 586
2016-01-08 14:39:07.973 HelloWorld.iOS[1060:485332] critical: 18  CoreGraphics                        0x26bb648d CGContextDelegateDrawImage + 44
2016-01-08 14:39:07.974 HelloWorld.iOS[1060:485332] critical: 19  CoreGraphics                        0x26c54137 CGContextDrawImageWithOptions + 274
2016-01-08 14:39:07.974 HelloWorld.iOS[1060:485332] critical: 20  CoreGraphics                        0x26bb643b CGContextDrawImage + 50
2016-01-08 14:39:07.974 HelloWorld.iOS[1060:485332] critical: 21  HelloWorld.iOS                      0x01e454a8 wrapper_managed_to_native_CoreGraphics_CGContext_CGContextDrawImage_intptr_CoreGraphics_CGRect_intptr + 144
2016-01-08 14:39:07.975 HelloWorld.iOS[1060:485332] critical: 22  HelloWorld.iOS                      0x01721f6c CoreGraphics_CGContext_DrawImage_CoreGraphics_CGRect_CoreGraphics_CGImage + 228
2016-01-08 14:39:07.975 HelloWorld.iOS[1060:485332] critical: 23  HelloWorld.iOS                      0x024fa440 NGraphics_CGContextCanvas_DrawImage_NGraphics_IImage_NGraphics_Rect_double + 1352
2016-01-08 14:39:07.975 HelloWorld.iOS[1060:485332] critical: 24  HelloWorld.iOS                      0x0000f570 HelloWorld_iOS_GlobeView_Draw_NGraphics_ICanvas_NGraphics_Rect + 1368
2016-01-08 14:39:07.975 HelloWorld.iOS[1060:485332] critical: 25  HelloWorld.iOS                      0x024e855c NControl_iOS_NControlViewRenderer_Draw_CoreGraphics_CGRect + 1220
2016-01-08 14:39:07.975 HelloWorld.iOS[1060:485332] critical: 26  HelloWorld.iOS                      0x004f62a8 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 256
2016-01-08 14:39:07.976 HelloWorld.iOS[1060:485332] critical: 27  HelloWorld.iOS                      0x025c22af mono_jit_runtime_invoke + 1150
2016-01-08 14:39:07.976 HelloWorld.iOS[1060:485332] critical: 28  HelloWorld.iOS                      0x0260896d mono_runtime_invoke + 88
2016-01-08 14:39:07.976 HelloWorld.iOS[1060:485332] critical: 29  HelloWorld.iOS                      0x0255ffb9 _ZL31native_to_managed_trampoline_25P11objc_objectP13objc_selectorPP11_MonoMethod6CGRectPKcS8_S8_ + 156
2016-01-08 14:39:07.976 HelloWorld.iOS[1060:485332] critical: 30  HelloWorld.iOS                      0x02583e51 -[NControl_iOS_NControlViewRenderer drawRect:] + 132
2016-01-08 14:39:07.977 HelloWorld.iOS[1060:485332] critical: 31  UIKit                               0x29d81a33 <redacted> + 386
2016-01-08 14:39:07.977 HelloWorld.iOS[1060:485332] critical: 32  QuartzCore                          0x27e003e1 <redacted> + 228
2016-01-08 14:39:07.977 HelloWorld.iOS[1060:485332] critical: 33  QuartzCore                          0x27de9ccf <redacted> + 1866
2016-01-08 14:39:07.977 HelloWorld.iOS[1060:485332] critical: 34  QuartzCore                          0x27ed7a0d <redacted> + 52
2016-01-08 14:39:07.978 HelloWorld.iOS[1060:485332] critical: 35  QuartzCore                          0x27de91fb <redacted> + 1170
2016-01-08 14:39:07.978 HelloWorld.iOS[1060:485332] critical: 36  QuartzCore                          0x27dcd3b1 <redacted> + 208
2016-01-08 14:39:07.978 HelloWorld.iOS[1060:485332] critical: 37  QuartzCore                          0x27dcd069 <redacted> + 24
2016-01-08 14:39:07.978 HelloWorld.iOS[1060:485332] critical: 38  QuartzCore                          0x27dcc581 <redacted> + 368
2016-01-08 14:39:07.978 HelloWorld.iOS[1060:485332] critical: 39  QuartzCore                          0x27dcc233 <redacted> + 614
2016-01-08 14:39:07.979 HelloWorld.iOS[1060:485332] critical: 40  QuartzCore                          0x27dc59ef <redacted> + 138
2016-01-08 14:39:07.980 HelloWorld.iOS[1060:485332] critical: 41  CoreFoundation                      0x25b24b21 <redacted> + 20
2016-01-08 14:39:07.980 HelloWorld.iOS[1060:485332] critical: 42  CoreFoundation                      0x25b22e17 <redacted> + 282
2016-01-08 14:39:07.980 HelloWorld.iOS[1060:485332] critical: 43  CoreFoundation                      0x25b23255 <redacted> + 972
2016-01-08 14:39:07.980 HelloWorld.iOS[1060:485332] critical: 44  CoreFoundation                      0x25a75bb9 CFRunLoopRunSpecific + 516
2016-01-08 14:39:07.981 HelloWorld.iOS[1060:485332] critical: 45  CoreFoundation                      0x25a759ad CFRunLoopRunInMode + 108
2016-01-08 14:39:07.981 HelloWorld.iOS[1060:485332] critical: 46  GraphicsServices                    0x26cefaf9 GSEventRunModal + 160
2016-01-08 14:39:07.981 HelloWorld.iOS[1060:485332] critical: 47  UIKit                               0x29d61fb5 UIApplicationMain + 144
2016-01-08 14:39:07.982 HelloWorld.iOS[1060:485332] critical: 48  HelloWorld.iOS                      0x01e1f6bc wrapper_managed_to_native_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 272
2016-01-08 14:39:07.982 HelloWorld.iOS[1060:485332] critical: 49  HelloWorld.iOS                      0x01563e3c UIKit_UIApplication_Main_string___intptr_intptr + 52
2016-01-08 14:39:07.982 HelloWorld.iOS[1060:485332] critical: 50  HelloWorld.iOS                      0x01563ce0 UIKit_UIApplication_Main_string___string_string + 204
2016-01-08 14:39:07.982 HelloWorld.iOS[1060:485332] critical: 51  HelloWorld.iOS                      0x0000e14c HelloWorld_iOS_Application_Main_string__ + 188
2016-01-08 14:39:07.983 HelloWorld.iOS[1060:485332] critical: 52  HelloWorld.iOS                      0x004f62a8 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 256
2016-01-08 14:39:07.983 HelloWorld.iOS[1060:485332] critical: 53  HelloWorld.iOS                      0x025c22af mono_jit_runtime_invoke + 1150
2016-01-08 14:39:07.983 HelloWorld.iOS[1060:485332] critical: 54  HelloWorld.iOS                      0x0260896d mono_runtime_invoke + 88
2016-01-08 14:39:07.983 HelloWorld.iOS[1060:485332] critical: 55  HelloWorld.iOS                      0x0260be47 mono_runtime_exec_main + 282
2016-01-08 14:39:07.983 HelloWorld.iOS[1060:485332] critical: 56  HelloWorld.iOS                      0x0268d3b4 xamarin_main + 2072
2016-01-08 14:39:07.984 HelloWorld.iOS[1060:485332] critical: 57  HelloWorld.iOS                      0x02594581 main + 112
2016-01-08 14:39:07.984 HelloWorld.iOS[1060:485332] critical: 58  libdyld.dylib                       0x25728873 <redacted> + 2
2016-01-08 14:39:07.984 HelloWorld.iOS[1060:485332] critical: 
=================================================================
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.
=================================================================
Comment 1 bobme981 2016-01-08 22:51:00 UTC
Note that because of the severe nature of the crash, normal try/catch exception handling is not available as a workaround. Execution never gets to the catch block.
Comment 2 bobme981 2016-01-09 01:32:00 UTC
The repro solution uses NControl and NGraphics packages to enable custom drawn controls in Xamarin.Forms. However, the code from these packages being used in this case is very minimal. You can see the code here:

Load PNG image:
https://github.com/praeclarum/NGraphics/blob/master/Platforms/NGraphics.Mac/ApplePlatform.cs#L74

Draw control:
https://github.com/chrfalch/NControl/blob/develop/NControl/NControl.iOS/NControlViewRenderer.cs#L113

Draw image:
https://github.com/praeclarum/NGraphics/blob/master/Platforms/NGraphics.Mac/ApplePlatform.cs#L480
Comment 3 Rolf Bjarne Kvinge [MSFT] 2016-01-11 13:01:10 UTC
Fixed.

You can work around the bug by loading PNG images like this: https://gist.github.com/rolfbjarne/1452c400fbbbe7da071f

maccore/master: cd47e51c4ba0717f5398c64f1efdebb016bb0e39
Comment 4 bobme981 2016-01-15 04:10:13 UTC
The workaround fixes the crash, but does not fix the rendering issue.

Filed a new bug #37713 for the rendering issue.