Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Xamarin Forms Multiple Animations Causes Crash

EddieLudemaEddieLudema USMember ✭✭

Hi folks! Really enjoying getting into Xamarin with my first legit app. And here's my first semi-legit question on the forums! I also posted on StackOverflow, but thought I should go straight to the source!

Is there some sort of limit I should be aware of when it comes to the number of consecutive and/or simultaneous animations, custom or otherwise, in Xamarin Forms?

Here's a simple example of what I'm dealing with:

protected void ShowAlertMessage(string message)
    lblAlertMessage.Text = message;

    this.AbortAnimation("AlertShow"); // crash happens with and without this...

    new Animation {
        { 0, 0.1, new Animation(v => AlertView.Opacity = v, 0.0, 1.0) },
        { 0.1, 0.6, new Animation(v => AlertView.Opacity = v, 1.0, 1.0) },
        { 0.6, 1.0, new Animation(v => AlertView.Opacity = v, 1.0, 0) },
    }.Commit(this, "AlertShow", length: 3000);

The animation itself works fine. The AlertView view fades in, sustains, then fades out. I call the function again after the animation is complete, and it works fine. I call the function again while the AlertView is in the middle of a running animation, and it's still fine - it restarts the animation. However, if I mash the button that calls ShowAlertMessage() super fast, without fail, the iPhone emulator crashes with the following stack trace (I'm just including the first handful of lines that seem pertinent):

2017-06-22 14:20:18.835 RootTuner.iOS[4810:234234] critical: Stacktrace:

2017-06-22 14:20:18.835 RootTuner.iOS[4810:234234] critical: at <0xffffffff>
2017-06-22 14:20:18.837 RootTuner.iOS[4810:234234] critical: at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend_float (intptr,intptr,single) [0x0000b] in <58a9bd8a3cbb4d0092bc0a767ff66c0f>:0
2017-06-22 14:20:18.837 RootTuner.iOS[4810:234234] critical: at CoreAnimation.CALayer.set_Opacity (single) [0x0000b] in /Users/builder/data/lanes/4691/d2270eec/source/xamarin-macios/src/build/ios/native/CoreAnimation/CALayer.g.cs:1714
2017-06-22 14:20:18.838 RootTuner.iOS[4810:234234] critical: at Xamarin.Forms.Platform.iOS.VisualElementTracker/<>c__DisplayClass23_0.b__0 () [0x0015a] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:178
2017-06-22 14:20:18.838 RootTuner.iOS[4810:234234] critical: at Xamarin.Forms.Platform.iOS.CADisplayLinkTicker.StartThread () [0x0001d] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\CADisplayLinkTicker.cs:57
2017-06-22 14:20:18.839 RootTuner.iOS[4810:234234] critical: at System.Threading.ThreadHelper.ThreadStart_Context (object) [0x00014] in /Library/Frameworks/Xamarin.iOS.framework/Versions/

And the Native Stacktrace:

2017-06-22 14:49:42.296 RootTuner.iOS[5311:253932] critical: 0 RootTuner.iOS 0x000000010cee9501 mono_handle_native_crash + 257
2017-06-22 14:49:42.296 RootTuner.iOS[5311:253932] critical: 1 RootTuner.iOS 0x000000010cef65d0 mono_sigsegv_signal_handler + 288
2017-06-22 14:49:42.297 RootTuner.iOS[5311:253932] critical: 2 libsystem_platform.dylib 0x0000000118ce6bba _sigtramp + 26
2017-06-22 14:49:42.297 RootTuner.iOS[5311:253932] critical: 3 ??? 0x00007f80c4353720 0x0 + 140191024363296
2017-06-22 14:49:42.297 RootTuner.iOS[5311:253932] critical: 4 UIKit 0x0000000111140178 -[UIViewAnimationState actionForLayer:forKey:forView:] + 99
2017-06-22 14:49:42.297 RootTuner.iOS[5311:253932] critical: 5 UIKit 0x000000011116b52e +[UIView(Animation) _defaultUIViewActionForLayer:forKey:] + 111
2017-06-22 14:49:42.298 RootTuner.iOS[5311:253932] critical: 6 UIKit 0x00000001119498ec -[UIView(UIKitManual) actionForLayer:forKey:] + 119
2017-06-22 14:49:42.298 RootTuner.iOS[5311:253932] critical: 7 QuartzCore 0x000000011acc54bc -[CALayer actionForKey:] + 437
2017-06-22 14:49:42.298 RootTuner.iOS[5311:253932] critical: 8 QuartzCore 0x000000011acc0ade _ZL12actionForKeyP7CALayerPN2CA11TransactionEP8NSString + 76
2017-06-22 14:49:42.298 RootTuner.iOS[5311:253932] critical: 9 QuartzCore 0x000000011acc0a6c _ZN2CA5Layer12begin_changeEPNS_11TransactionEjRP11objc_object + 140
2017-06-22 14:49:42.298 RootTuner.iOS[5311:253932] critical: 10 QuartzCore 0x000000011acc0e04 _ZN2CA5Layer6setterEj12_CAValueTypePKv + 164
2017-06-22 14:49:42.299 RootTuner.iOS[5311:253932] critical: 11 QuartzCore 0x000000011accc351 -[CALayer setOpacity:] + 43
2017-06-22 14:49:42.299 RootTuner.iOS[5311:253932] critical: 12 RootTuner.iOS 0x000000010d0ab429 xamarin_dyn_objc_msgSend + 217

What am I doing wrong? It does the same thing in other situations using the simple .FadeTo() and .ScaleTo() methods. The animations work, but too many causes the system to crash.

I'm using Visual Studio for Mac (Community) 7.0.1 compiling for iOS. Let me know if more specs are needed. I'm just hoping there's an animation "best practice" I'm missing!

Best Answer


  • JensDemeyJensDemey USMember ✭✭


    I'm pretty sure I've ran into this problem before. If I'm not mistaken it occurs when you stop and start an animation within an interval of 33 ms (or 16 not sure). I think that I just copied over the methods and put a try catch block around it. All I remember is that it had something to do with a boolean that had not yet changed when the animation was about to start/stop.

  • EddieLudemaEddieLudema USMember ✭✭

    Thanks, folks for the empathy! None of my animations are any less than 100ms, so unfortunately that wasn't the issue. I messed around with the idea of iOS zombies happening - trying to hit something that had been garbage collected. I found a bit of code that forced the garbage collector to run every few seconds to see if the crashes would happen more frequently, which would be an indication that iOS was in fact trying to hit garbage collected items. Sure enough, the crashes became a lot more frequent and consistent. Not sure what I could do about, since I'm not removing anything in my code -- it has to something inside the guts that I can't get to.

    I ended up removing any "unnecessary" animations and things seem to be fine... It'll be great when animation becomes a more solid feature in Forms!

Sign In or Register to comment.