0

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.

scenekit exc_bad_access

Lukas
  • 1,346
  • 7
  • 24
  • 49
  • What does your generateClouds do? I guess that you run into an error because it requires something, which in fact you just removed one step earlier. Trying putting '//' before [self generateClouds]; and running it again. – El Tomato Mar 22 '15 at 10:34
  • Thank's for you're comment. It generates new clouds, if needed. (This is basically the first part of the code posted here) I've also tried to uncomment it, but it ends up with the same error. It's kinda weird. The solution I came up with was to never remove the nodes but instead reuse them.. but it's kinda ugly.. :/ – Lukas Mar 22 '15 at 10:39
  • Switch on NSZombies in your build scheme. Your crash is probably due to an object getting over-released - using zombies will tell you exactly which one it is http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode – Rich Tolley Mar 22 '15 at 11:06
  • Thank's for help! I found the reason for the crash.. But it's somehow weird :) Fixed it now! – Lukas Mar 22 '15 at 11:27
  • What was the reason? @LucèBrùlè – Stéphane de Luca Jan 23 '16 at 11:55
  • Can't really tell you. It seemed to be a bug in the SpriteKit Framework :/ Pretty strange... maybe i'm jsut to dumb to understand it ^^ – Lukas Jan 23 '16 at 16:01

1 Answers1

0

I stored some velocity-data in the physicsBody, which caused the crash. I'm not quite sure why, but after removing these lines, it worked. Maybe it will help someone else too..

clusterNode.physicsBody = [[SCNPhysicsBody alloc] init];
clusterNode.physicsBody.velocity= SCNVector3Make(clusterVelocityX, clusterVelocityY, clusterVelocityZ);
Lukas
  • 1,346
  • 7
  • 24
  • 49