I hava an NSMutableArray
with my CCNodes in it. I want to paint and unpaint them on my CCScene, using [scene addChild:]
and [CCNode removeFromParentAndCleanUp:YES]
.
My problem shows up when it's checking if any of my objects has a parent and it is deleted in another class at the same time. You can see this code, and it always crashes there:
for(int y = negativeY; y < positiveY; y++){
for(int x = negativeX; x < positiveX; x++){
if([[self.rockArray objectAtIndex:y] objectAtIndex:x] != nil){ //checking if object is not null
if([[[self.rockArray objectAtIndex:y] objectAtIndex:x] parent] == nil){ //Crashes here!
NSLog(@"Rock is not visible. Painting it");
[listener addChild:[[self.rockArray objectAtIndex:y] objectAtIndex:x]];
}else{
NSLog(@"Rock is already visible.");
}
}
}
}
The Log message is *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull parent]: unrecognized selector sent to instance 0x351d6b0'
Maybe we could solve this using Semaphores
? (if so, could you please post me an example in Objective C?)
Thank you for your time!
nil
instead of[NSNull null]
. Thank you. – aramusss