2

My app crashes in XCode after idling for about 5-7 minutes. I'm sure it's something to do with the animation used for the loading screen - I pasted the code below.

I tried enabling Zombie Objects to see if it was a call to a released object, and attached screenshots of the debug window when it crashed.

By the way - if I press 'resume' the app continues to function normally..

Edit: this is a first. A global breakpoint I set was stopped on the line [UIView animateWithDuration:0.2... and this is the output code (it hard crashed this time):

XYZ(14098,0xac3eaa28) malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug 2013-02-23 13:19:36.653 XYZ[14098:c07] *** Terminating app due to uncaught exception 'NSMallocException', reason: '*** -[NSObject allocWithZone:]: attempt to allocate object of class 'UIViewAnimationState' failed'
*** First throw call stack: (0x1cf3012 0x17e8e7e 0x1d7e1a4 0x17fca6b 0x17fca55 0x3acceb 0x3baeec 0x3bb1a7 0x37785 0x3badf6 0x3add66 0x3adf04 0x10fc7d8 0x196d014 0x195d7d5 0x1c99af5 0x1c98f44 0x1c98e1b 0x28f17e3 0x28f1668 0x36fffc 0x28fd 0x2825) libc++abi.dylib: terminate called throwing an exception

- (void)startAnimating
{   
    _isAnimating = YES;
    float rotationAngle = 360.0 / 3;
    [UIView animateWithDuration:0.5
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^
    {
        self.marks.transform = CGAffineTransformRotate(self.marks.transform,
                                                       ((rotationAngle + 10) * (M_PI / 180.0)));
//        self.marks.transform = CGAffineTransformMakeRotation((rotationAngle + 10) * (M_PI / 180.0));
    }
                     completion:^(BOOL finished)
    {
        [UIView animateWithDuration:0.2
                              delay:0.0
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^
        {
            self.marks.transform = CGAffineTransformRotate(self.marks.transform,
                                                           -10 * (M_PI / 180.0));
//            self.marks.transform = CGAffineTransformMakeRotation(-10 * (M_PI / 180.0));
        }
                         completion:^(BOOL finished)
        {
            self.marks.transform = CGAffineTransformIdentity;
            [self startAnimating];
        }];
    }];
}

The screenshot when it crashed normally:

Screenshot with NSZombieObjects disabled

The screenshot when NSZombieObjects is enabled:

Screenshot with NSZombieObjects enabled

Scott Fister
  • 1,213
  • 12
  • 24
  • 3
    It'd be more efficient to set this up manually as a repeating `CAKeyframeAnimation` but putting that aside, at a hunch: what happens if you switch `[self startAnimating]` to `[self performSelector:@selector(startAnimating) withObject:nil afterDelay:0.0]` — just to rule out the possibility that the old internal modal setup for animation blocks doesn't somehow fail when you try to create a new one within the callback from an old one. – Tommy Feb 23 '13 at 03:10
  • Thanks for your suggestion. After changing the code to perform selector, I still get a crash - though now the log's a little different: [link](http://i.imgur.com/u3MYE9h.png). Haven't used Keyframeanimation before, will read up on it. – Scott Fister Feb 23 '13 at 05:27

1 Answers1

1

The completion block of your second animation is recursively calling startAnimating. I would think that is the cause of the problem. You should use a loop instead or create a repeating animation.

progrmr
  • 75,956
  • 16
  • 112
  • 147
  • Removing the recursive call to startAnimating, and instead adding `options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionRepeat` seems to have fixed the issue. However, the way the loading view works is it's simply hidden and shown when needed. I found I also had to manually `removeAllAnimation`s and call startAnimating in the hide/show method calls, otherwise the when it was shown again it would not animate. – Scott Fister Feb 24 '13 at 03:35