I'm currently working on a small game, in which i'm animating a few clouds in the background. I'd like to remove these clouds afterwards by calling removeFromParentNode
on the main SCNNode of the cloud. As I've read in the doc's this should remove the Node and all it's childnodes, animations, etc.. The problem is that it always fires a EXC_BAD_ACCESS after calling removeFromParentNode..
SCNNode * clusterNode = [self getCloud];
clusterNode.position = SCNVector3Make(baseX, baseY, baseZ);
CABasicAnimation *moveAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
moveAnimation.duration = 10.0;
moveAnimation.repeatCount = 0;
moveAnimation.fromValue = [NSNumber numberWithFloat: baseX];
moveAnimation.toValue=[NSNumber numberWithFloat: -80.0];
moveAnimation.removedOnCompletion = NO;
moveAnimation.fillMode = kCAFillModeForwards;
[moveAnimation setValue: clusterNode forKey:@"rootNode"];
moveAnimation.delegate = self;
[clusterNode addAnimation: moveAnimation forKey:nil];
[cloudRootNode addChildNode: clusterNode];
I'm then removing the cloud in the in the animation remove delegate.. (I've tried it in other places too, same result..)
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
NSLog(@"Animation done.");
SCNNode * rootNode = [anim valueForKey: @"rootNode"];
[rootNode removeFromParentNode];
[self generateClouds];
}
Where can I start to debug such a error? Is there anything I'm obviously doing wrong? Thank's for you're help!
EDIT: I've added the err as img.