EXC_BAD_ACCESS when using CoreAnimation

I am using CoreAnimation to animate a UIImageView (Bezier curve animation). Here is my code:

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; pathAnimation.calculationMode = kCAAnimationCubic; pathAnimation.fillMode = kCAFillModeForwards; pathAnimation.removedOnCompletion = NO; CGPoint endPoint = originalPosition; UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:star.layer.position]; [path addQuadCurveToPoint:endPoint controlPoint:CGPointMake(star.layer.position.x, endPoint.y)]; pathAnimation.path = path.CGPath; [star.layer addAnimation:pathAnimation forKey:@"moveToScorebarAnimation"]; 

As a result, I get EXC_BAD_ACCESS (code = 2, address = 0x0) using stacktrace:

 CoreGraphics`CG::Path::apply(void*, void (*)(void*, CGPathElementType, CGPoint const*)) const: 0x613c06: pushl %ebp 0x613c07: movl %esp, %ebp 0x613c09: subl $24, %esp 0x613c0c: movl 8(%ebp), %eax 0x613c0f: movl (%eax), %ecx 0x613c11: movl (%ecx), %eax 0x613c13: movl 16(%ebp), %edx 0x613c16: movl %edx, 8(%esp) 0x613c1a: movl 12(%ebp), %edx 0x613c1d: movl %edx, 4(%esp) 0x613c21: movl %ecx, (%esp) 0x613c24: calll *64(%eax) 0x613c27: addl $24, %esp 0x613c2a: popl %ebp 0x613c2b: ret 

I tried to use different guides for this, but the application crashes the same. I can’t understand where my fault is. Any help would be appreciated, thanks.

R. S. Here is a similar error but, unfortunately, it is solved simply by removing the animation.

R. PS Arc included. Also, if I comment on pathAnimation.path = path.CGPath; the line, the accident does not appear, as well as the animation (which is not surprising :)).

+1
source share
2 answers

This error will be selected if the object does not exist in memory. Make sure the initialization is correct. make sure you initialize Layer..etc.. ?

The best way is to use BreakPoint to find out where your app gets the handouts.

I am not sure, but it may be useful for you.

Add animation as

 CAAnimationGroup *group = [CAAnimationGroup animation]; group.animations = [NSArray arrayWithObjects: pathAnimation,nil]; group.duration = 7.0; //The total time of the animations, don't know if redundant group.delegate = self; [self.layer addAnimation:group forKey:@"path"]; 
+1
source

Replace CAKeyframeAnimation with CABasicAnimation:

  CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"position"]; pathAnimation.fromValue = [NSValue valueWithCGPoint:star.layer.position]; pathAnimation.toValue = [NSValue valueWithCGPoint:endPoint]; pathAnimation.fillMode = kCAFillModeForwards; pathAnimation.removedOnCompletion = NO; 

It seems to be Apple's mistake

+1
source

Source: https://habr.com/ru/post/1498990/


All Articles