Bug 41896 - [iOS] ScrollToAsync or PresentViewControllerAsync runtime crash
Summary: [iOS] ScrollToAsync or PresentViewControllerAsync runtime crash
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-06-16 13:52 UTC by eusebiu.marcu
Modified: 2017-05-01 16:45 UTC (History)
8 users (show)

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

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:

Description eusebiu.marcu 2016-06-16 13:52:12 UTC
At random times, when ScrollToAsync or PresentViewControllerAsync are called I get this runtime crash:

pp[24977:8472787] critical: Stacktrace:

App[24977:8472787] critical: at <0xffffffff>
App[24977:8472787] critical: at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend_CATransform3D (intptr,intptr,CoreAnimation.CATransform3D) 
App[24977:8472787] critical: at CoreAnimation.CALayer.set_Transform (CoreAnimation.CATransform3D) [0x0000b] in /Users/builder/data/lanes/2689/962a0506/source/maccore/src/build/ios/native/CoreAnimation/CALayer.g.cs:2305
App[24977:8472787] critical: at Xamarin.Forms.Platform.iOS.VisualElementTracker/<>c__DisplayClass25_0.b__0 () 
App[24977:8472787] critical: at Xamarin.Forms.Platform.iOS.CADisplayLinkTicker.StartThread () 
App[24977:8472787] critical: at System.Threading.ThreadHelper.ThreadStart_Context (object) [0x00017] in /Users/builder/data/lanes/2689/962a0506/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/thread.cs:68
App[24977:8472787] critical: at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) [0x00081] in /Users/builder/data/lanes/2689/962a0506/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/executioncontext.cs:581
App[24977:8472787] critical: at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) [0x00000] in /Users/builder/data/lanes/2689/962a0506/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/executioncontext.cs:530
App[24977:8472787] critical: at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object) [0x00031] in /Users/builder/data/lanes/2689/962a0506/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/executioncontext.cs:519
App[24977:8472787] critical: at System.Threading.ThreadHelper.ThreadStart () [0x0000b] in /Users/builder/data/lanes/2689/962a0506/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/thread.cs:105
App[24977:8472787] critical: at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr)

A symbolicated crash can be found here: https://gist.github.com/eusebiu/e8f65ad12d8126dbc308617c524b0bcf
Comment 1 eusebiu.marcu 2016-06-16 13:55:03 UTC
Xamarin Studio 6.0 (5174) - stable
Xamarin Forms 2.2.45
iOS 9.3
Xcode 7.3.1
Comment 2 eusebiu.marcu 2016-07-15 06:19:01 UTC
Also noticed that the same error appears when opening a simple Picker.
Comment 3 Rui Marinho 2016-08-09 10:29:19 UTC
Needs Info

Thank you for taking the time to submit the bug. We tried to reproduce the issue you reported but were unable given the description.

If you could please attach a reproduction to the bug by starting with a clean Xamarin.Forms project and adding just the code necessary to demonstrate the issue, we would very much appreciate it.

For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d

Warm regards,

Xamarin Forms team
Comment 4 eusebiu.marcu 2016-08-09 10:59:54 UTC
Thanks for looking at this!

Unfortunately, I cannot reproduce it in a normal/simple XF project.

My local fix (though does not always work) was to add a Thread.Sleep(100) before await PresentViewControllerAsync(...). This clearly indicates that there is a threading (or memory) issue in that part of the platform.

The strange thing is that the Picker is also impacted (again, randomly)... so it's somehow a general problem with the code that does the (3D) effects/animations.
Comment 5 Rui Marinho 2016-08-09 11:02:10 UTC
We can't reproduce this in our testing . It will be really hard to understand without having some code to look at , the stack trace doesn't provide us with enough information.
Comment 6 eusebiu.marcu 2016-10-30 19:02:39 UTC
Thanks for looking at this!

Can you help me setting up a debug version of Xamarin Forms and Xamarin.iOS? 
I'd like to be able to debug Xamarin to better provide information for you.
Comment 7 Samantha Houts [MSFT] 2016-11-18 18:41:22 UTC

You can pull down a complete copy of the source from https://github.com/xamarin/Xamarin.Forms. The README.md contains a set of instructions to help you get it running. Please let us know if you have any questions. 

Comment 8 eusebiu.marcu 2016-11-30 18:24:33 UTC
I do not think the XF is enough since the trace goes way into Xamarin.iOS to the runtime (ObjCRuntime.Messaging.void_objc_msgSend_CATransform3D).

The XF readme is mentioning that VS is required and I'd like to debug it on macOS (the same for Xamarin.iOS including the native part - like native/CoreAnimation/CALayer.g.cs).
Comment 9 Samantha Houts [MSFT] 2016-12-01 18:06:06 UTC
VS is required for Windows development, but you may debug the iOS portions using Xamarin Studio on Mac.
Comment 13 Tom Gilder 2017-04-11 14:28:30 UTC
I've just come across this crash, it seems to occur when:

 * A UIScrollView is already animating (from a user swipe)
 * You call ScrollToAsync on it (before the existing animation has finished)

I'll see if I can come up with a repro for you.
Comment 14 Bright Lee 2017-05-01 08:39:07 UTC
Exactly same issue. 
UIScrollView and Picker.

Thank God. I'm not the only one.
Comment 15 Ammar Mheir 2017-05-01 16:45:16 UTC
The reason we were getting this crash was because of an animation that was running on the main thread while the scroll was happening. In the case of the original post of this bug report, there was a custom ActivityIndicator (spinning loading icon) that continued to run even after falling out of scope when navigating away from the page were it was being used. It was being hidden but the animation task did not stop. 

The way we went about troublehsoting this was by running the Xamarin Profiler and checking the "Performance" tool. You can navigate throughout the app and see if there is anything running in the background, specifically on the main UI thread. In our case, the app was not being interacted with and was idle on one of the pages, yet we observed a process running on the main thread. This task running on the Main UI thread eventually caused this crash if another animation was about to occur on the UI. (Such as scrolling, changing values of picker, clicking a button that had an icon set to it, or anything else that required some sort of animation to display on the UI)

My suspicion is that this was a multithreading issues and that the UI thread was originally being used when yet another animation task was trying to run on that same thread, using the same animation tasks such as CADisplayLinkTicker (Core Animation).

Check to see if there is anything running on the Main thread when your about to scroll or use the picker, this was the cause of this error on our end. 

-Setting to Resolved as this was the solution for the original poster and was not a bug within the framework.