My App is giving the following output :
Terminating app due to uncaught exception 'Attemped to add nil node', reason: 'Attemped to add nil node to parent: <SKScene> name:'(null)' frame:{{0, 0}, {320, 568}}'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101a7b495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001017da99e objc_exception_throw + 43
2 CoreFoundation 0x0000000101a7b2ad +[NSException raise:format:] + 205
3 SpriteKit 0x0000000101271622 -[SKNode addChild:] + 161
4 Jump'n'Run Game 0x00000001000057cb -[MyScene BodenHindernisse] + 9067
5 SpriteKit 0x00000001012905e0 -[SKPerformSelector updateWithTarget:forTime:] + 85
6 SpriteKit 0x000000010124f68a _ZN11SKCSequence27cpp_updateWithTargetForTimeEP9SKCSprited + 66
7 SpriteKit 0x000000010124ac32 _ZN9SKCRepeat27cpp_updateWithTargetForTimeEP9SKCSprited + 40
8 SpriteKit 0x000000010128968b _ZN9SKCSprite6updateEd + 235
9 SpriteKit 0x0000000101255a6f -[SKScene _update:] + 101
10 SpriteKit 0x00000001012688c2 -[SKView(Private) _update:] + 223
11 SpriteKit 0x00000001012668a7 -[SKView renderCallback:] + 869
12 SpriteKit 0x0000000101267b7d -[SKView layoutSubviews] + 364
13 UIKit 0x00000001002bc993 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354
14 QuartzCore 0x00000001040f5802 -[CALayer layoutSublayers] + 151
15 QuartzCore 0x00000001040ea369 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
16 QuartzCore 0x00000001040f5736 -[CALayer layoutIfNeeded] + 162
17 UIKit 0x0000000100362a22 -[UIViewController window:setupWithInterfaceOrientation:] + 264
18 UIKit 0x0000000100299cad -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 4360
19 UIKit 0x0000000100298b9f -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 36
20 UIKit 0x0000000100298aef -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 101
21 UIKit 0x0000000100297dfe -[UIWindow _updateToInterfaceOrientation:duration:force:] + 377
22 UIKit 0x000000010035670a -[UIViewController _tryBecomeRootViewControllerInWindow:] + 147
23 UIKit 0x0000000100292b1b -[UIWindow addRootViewControllerViewIfPossible] + 490
24 UIKit 0x0000000100292c70 -[UIWindow _setHidden:forced:] + 282
25 UIKit 0x000000010029bffa -[UIWindow makeKeyAndVisible] + 51
26 UIKit 0x0000000100257c98 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1788
27 UIKit 0x000000010025ba0c -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 660
28 UIKit 0x000000010026cd4c -[UIApplication handleEvent:withNewEvent:] + 3189
29 UIKit 0x000000010026d216 -[UIApplication sendEvent:] + 79
30 UIKit 0x000000010025d086 _UIApplicationHandleEvent + 578
31 GraphicsServices 0x0000000103c8471a _PurpleEventCallback + 762
32 GraphicsServices 0x0000000103c841e1 PurpleEventCallback + 35
33 CoreFoundation 0x00000001019fd679 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
34 CoreFoundation 0x00000001019fd44e __CFRunLoopDoSource1 + 478
35 CoreFoundation 0x0000000101a26903 __CFRunLoopRun + 1939
36 CoreFoundation 0x0000000101a25d83 CFRunLoopRunSpecific + 467
37 UIKit 0x000000010025b2e1 -[UIApplication _run] + 609
38 UIKit 0x000000010025ce33 UIApplicationMain + 1010
39 Jump'n'Run Game 0x00000001000085b3 main + 115
40 libdyld.dylib 0x00000001021125c9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
So basically, my app is trying to spawn obstacles in a row forever, but there seems to be an error in my code. I used the SpriteNode 'Enemy' as a 'head'Subclass, so that I got 1 Enemy, and the cases define the texture of the Enemy. Also shortened, because the problem seems to be in the spawn definition.
-(id)initWithSize:(CGSize)size {
.....
SKAction * Spawn = [SKAction performSelector:@selector(BodenHindernisse) onTarget:self];
SKAction * Delay = [SKAction waitForDuration:2];
SKAction * SpawnThenDelay = [SKAction sequence:@[Spawn, Delay]];
SKAction * SpawnThenDelayForever = [SKAction repeatActionForever:SpawnThenDelay];
[self runAction:SpawnThenDelayForever];
....
}
-(void)BodenHindernisse {
switch (arc4random_uniform(4)){
case 0:
if(Day){
Feind = Steine;
Steine = [SKSpriteNode spriteNodeWithImageNamed:@"Stein.png"];
Steine.size = CGSizeMake(50, 55);
Steine.zPosition = 2;
Steine.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:16];
Steine.physicsBody.dynamic = NO;
Steine.physicsBody.allowsRotation = NO;
Steine.physicsBody.usesPreciseCollisionDetection = YES;
Steine.physicsBody.restitution = 0;
Steine.physicsBody.categoryBitMask = HindernissCategory;
Steine.physicsBody.collisionBitMask = BodenCategory | MenschCategory;
Steine.physicsBody.contactTestBitMask = BodenCategory | MenschCategory;
Feind.position = CGPointMake(self.frame.size.width * 1.25, Boden.position.y + 69);
}
if(Night){
Feind = Zombie;
Zombie = [SKSpriteNode spriteNodeWithImageNamed:@"Zombie.png"];
Zombie.size = CGSizeMake(50, 50);
Zombie.zPosition = 2;
Zombie.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(30, 50)];
Zombie.physicsBody.dynamic = NO;
Zombie.physicsBody.allowsRotation = NO;
Zombie.physicsBody.usesPreciseCollisionDetection = YES;
Zombie.physicsBody.restitution = 0;
Zombie.physicsBody.velocity = CGVectorMake(0, 0);
Zombie.physicsBody.categoryBitMask = HindernissCategory;
Zombie.physicsBody.collisionBitMask = BodenCategory | MenschCategory;
Zombie.physicsBody.contactTestBitMask = BodenCategory | MenschCategory;
Feind.position = CGPointMake(self.frame.size.width * 1.25, Boden.position.y + 75);
}
break;
case 1:
if(Day){
Feind = MenschSchwert;
SKTexture * MenschSTexture1 = [SKTexture textureWithImageNamed:@"MenschSchwert1"];
MenschSTexture1.filteringMode = SKTextureFilteringNearest;
SKTexture * MenschSTexture2 = [SKTexture textureWithImageNamed:@"MenschSchwert2"];
MenschSTexture2.filteringMode = SKTextureFilteringNearest;
SKAction * Run = [SKAction repeatActionForever:[SKAction animateWithTextures:@[MenschSTexture1, MenschSTexture2] timePerFrame:0.25]];
MenschSchwert = [SKSpriteNode spriteNodeWithTexture:MenschSTexture1];
MenschSchwert.size = CGSizeMake(50, 50);
MenschSchwert.zPosition = 2;
MenschSchwert.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(40, 50)];
MenschSchwert.physicsBody.dynamic = NO;
MenschSchwert.physicsBody.allowsRotation = NO;
MenschSchwert.physicsBody.usesPreciseCollisionDetection = YES;
MenschSchwert.physicsBody.restitution = 0;
MenschSchwert.physicsBody.velocity = CGVectorMake(0, 0);
[MenschSchwert runAction:Run];
MenschSchwert.physicsBody.categoryBitMask = HindernissCategory;
MenschSchwert.physicsBody.collisionBitMask = BodenCategory | MenschCategory;
MenschSchwert.physicsBody.contactTestBitMask = BodenCategory | MenschCategory;
Feind.position = CGPointMake(self.frame.size.width * 1.25, Boden.position.y + 75);
}
break;
case 2:
Feind = Block;
Block = [SKSpriteNode spriteNodeWithImageNamed:@"Block.png"];
Block.size = CGSizeMake(40, 35);
Block.zPosition = 2;
Block.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(30, 35)];
Block.physicsBody.dynamic = NO;
Block.physicsBody.allowsRotation = NO;
Block.physicsBody.usesPreciseCollisionDetection = YES;
Block.physicsBody.restitution = 0;
Block.physicsBody.velocity = CGVectorMake(0, 0);
Block.physicsBody.categoryBitMask = LuftHindernissCategory;
Block.physicsBody.collisionBitMask = MenschCategory;
Block.physicsBody.contactTestBitMask = MenschCategory;
Feind.position = CGPointMake(self.frame.size.width * 1.25, Boden.position.y + 110);
break;
case 3:
Feind = Stachel;
Stachel = [SKSpriteNode spriteNodeWithImageNamed:@"Stachel.png"];
Stachel.size = CGSizeMake(60, 60);
Stachel.zPosition = 2;
Stachel.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(40, 45)];
Stachel.physicsBody.dynamic = NO;
Stachel.physicsBody.allowsRotation = NO;
Stachel.physicsBody.usesPreciseCollisionDetection = YES;
Stachel.physicsBody.restitution = 0;
Stachel.physicsBody.velocity = CGVectorMake(0, 0);
Stachel.physicsBody.categoryBitMask = LuftHindernissCategory;
Stachel.physicsBody.collisionBitMask = MenschCategory;
Stachel.physicsBody.contactTestBitMask = MenschCategory;
Feind.position = CGPointMake(self.frame.size.width * 1.25, Boden.position.y + 100);
break;
default:
break;
}
SKAction * actionMove = [SKAction moveToX:-100 duration:5];
SKAction * actionMoveDone = [SKAction removeFromParent];
[Feind runAction:[SKAction repeatActionForever:[SKAction sequence:@[actionMove,actionMoveDone]]]];
[self addChild:Feind];
}
As error description states, you are trying to add an SKNode
, which already has a parent. Make sure that parent
is nil
before adding.
Add exception breakpoint to locate the exact line, where the error occurs.
PS: Why did you omit a necessary parts of your code? It's always better to paste more code, than less.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments