nicklockwood / AutoCoding

AutoCoding is a category on NSObject that provides automatic support for NSCoding and NSCopying to every object.
Other
1.07k stars 131 forks source link

AutoCoding causes crash when using Core Animation #7

Closed turovyv closed 10 years ago

turovyv commented 11 years ago

Hi

In the app I'm developing I use Core Animation to animate a view's layer position like this:

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.repeatCount = 0;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
pathAnimation.duration = duration;

UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.bounds.size.width / 2, self.bounds.size.height)
                                                     radius:kArcRadius
                                                 startAngle:DEGREES_TO_RADIANS(-165)
                                                   endAngle:DEGREES_TO_RADIANS(-15)
                                                  clockwise:YES];
pathAnimation.path = CGPathCreateCopy(path.CGPath);

[self.timerLabel.layer addAnimation:pathAnimation forKey:kArcAnimationKey];

After adding AutoCoding, the app crashes with EXC_BAD_ACCESS. Here is the stack trace:

#0  0x2f193d2e in CG::Path::apply(void*, void (*)(void*, CGPathElementType, CGPoint const*)) const ()
#1  0x2f193d22 in CGPathApply ()
#2  0x31551e10 in CA::Render::Path::new_path(CGPath const*, bool) ()
#3  0x3153266a in -[CAKeyframeAnimation _setCARenderAnimation:layer:] ()
#4  0x31532566 in -[CAKeyframeAnimation _copyRenderAnimationForLayer:] ()
#5  0x31510b4a in CA::Layer::commit_animations(CA::Transaction*, double (*)(CA::Layer*, double, void*), void (*)(CA::Layer*, CA::Render::Animation*, void*), void (*)(CA::Layer*, void**, void*), void*) ()
#6  0x3150c33a in CA::Context::commit_layer(CA::Layer*, unsigned int, unsigned int, void*) ()
#7  0x3150931a in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#8  0x315092b8 in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#9  0x315092b8 in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#10 0x315092b8 in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#11 0x315092b8 in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#12 0x315092b8 in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#13 0x315092b8 in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#14 0x315092b8 in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#15 0x315092b8 in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#16 0x315092b8 in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#17 0x31507634 in CA::Context::commit_transaction(CA::Transaction*) ()
#18 0x3150710e in CA::Transaction::commit() ()
#19 0x31500e3c in CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) ()
#20 0x2f0dd1d4 in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#21 0x2f0dab78 in __CFRunLoopDoObservers ()
#22 0x2f0daeba in __CFRunLoopRun ()
#23 0x2f045ce6 in CFRunLoopRunSpecific ()
#24 0x2f045aca in CFRunLoopRunInMode ()
#25 0x33d13282 in GSEventRunModal ()
#26 0x318e7a40 in UIApplicationMain ()

I guess methods defined in the category on NSObject somehow interfere with internal logic of CA classes.

nicklockwood commented 11 years ago

Hmm, I'm guessing that this is something to do with the NSCopying logic. I had issues with this and CoreData previously.

juanchoc21 commented 10 years ago

I'm experiencing exactly the same issue (took me a while to figure it out).

nicklockwood commented 10 years ago

I've removed built-in NSCopying support. It's easy to add yourself if needed.