Search code examples
iphonecocoa-touchipadcore-animation

UIView Animation <Not Fetched> Crashing


My program moves an object along CGPoints. When a new amount of CGPoints are created it moves to the new points just fine. After about 5-10 object changes my application crashes and Xcode gets the beach ball.

Here is the animation:

-(void)animateDot {
    double x1 = dotMotion.center.x;
    double y1 = dotMotion.center.y;
    double x2 = (*doodlePoints)[dotLocation].x;
    double y2 = (*doodlePoints)[dotLocation].y;
    dist = sqrt(((x2 - x1)*(x2 - x1)) + ((y2 - y1)*(y2 - y1))); 
    if (dist < 0.01){
        dist = 1;
    }
    delay = dist/100.0;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDidStopSelector:@selector(animateDot)];
    [UIView setAnimationDuration:delay];
    dotMotion.center = (*doodlePoints)[dotLocation];
    if (dotLocation == doodlePoints->size()-1){
        dotMotion.bounds = CGRectMake(0, 0, 16, 16);
    } else {
        dotMotion.bounds = CGRectMake(0, 0, 8, 8);
    }
    [UIView commitAnimations];
    dotLocation = (dotLocation +1)%doodlePoints->size();
    if (dotLocation == 0 && stopAnimation != YES){
        dotLocation = (dotLocation +1)%doodlePoints->size();
    }
}

The button that you click for a new object has this: (and I do call isAnimating == TRUE once, and never call it false, so it shouldn't be doing animationDot again).

    if (isAnimating == TRUE) {
} else {
    [doodlePad animateDot];
}

My Errors include:

Warning: Unable to reach Previous state:

Also the stack shows a very large amount of (a couple thousand)

# <Not Fetched> //# = 1 to X amount

and also my stack starts with:

0 szone_malloc_should_clear
1 malloc_zone_malloc
2 _CFRuntimeCreateInstance
3 CFBasicHashCreate
4 __CFDictionaryCreateGeneric
5 CFDictionaryCreate
6 -[__NSPlaceholderDictionary int.. //I can't see the rest
7 +[NSDictionary dictionaryWithObj... //as above

then 8 through 100 has

# -[DoodlePad animateDot]
# -[UIViewAnimationState sendDel... //can't see the rest
# -[UIViewAnimationState popAni... //above

after this its all # <Not Fetched>

I have a feeling I need a way of releasing memory or remove the animation before the next CGPoints are created.

Can you explain what means? I couldn't find anyone with an error like this on Google. How can this crash be fixed?


Solution

  • Your selector is of the wrong form. It should accept three parameters :::. The other thing is that you are doing some heavy stuff with heavy objects (UI objects are heavy). It looks like your delay may take values as small as 0.01 (and smaller!!!). (Its not a delay, but duration in your case.) This sort of animation does not make sense, as fps on iPhone is 60.

    (Are you trying to replace game loop with animations? :))