1

I'm creating a unscramble words game.

I've reached the stage where I can save/load the game using:

  • (void)encodeWithCoder:(NSCoder *)aCoder

  • (instancetype)initWithCoder:(NSCoder *)aDecoder

When I save / load the game the first time there's no problem. When I press the home button the second time the app crashes & I end up with an error that I don't know how to understand.

What does this mean?

2014-01-11 18:23:12.254 GameTest[16622:70b] Terminating app due to uncaught exception

'Attemped to add nil node', reason: 'Attemped to add nil node to parent: <SKNode> name:'(null)' position:{0, 0} accumulatedFrame:{{inf, inf}, {inf, inf}}'

I don't know where the error occurs in my code.

Cheers Luke

yasmuru
  • 1,178
  • 2
  • 20
  • 42
  • it means addChild was called with parameter being nil. Add xcode exception breakpoint, if the error is in your code it'll show you – CodeSmile Jan 11 '14 at 09:07

2 Answers2

0

Thanks LearnCocos2D,

The error is arcane (my view) in it's details.

The problem was in how I dealt with the "bodyWithEdgeLoop" boundary.

The problem was also to do with:

(void)encodeWithCoder:(NSCoder *)aCoder

and

(instancetype)initWithCoder:(NSCoder *)aDecoder

methods.

I'm using Ray Wenderlich's iOS Games by Tutorials book & I made a mistake in the "initWithCoder" method.

I had removed & replaced the edge loop body in the "encodeWithCoder" method, but hadn't created it in the "initWithCoder" method.

So that is the solution. When saving a game the edge body loop must be removed & replaced in the "encodeWithCoder" method, but also has to be created in the "initWithCoder" method.

The biggest problem is that Xcode didn't point to any line in my code. I just did this on a "hunch".

Hope it helps.

0

I've ran into a similar issue that seems to affect some types of iPad. The scene was trying to add nil child.

Adding an exception handling block seems to have fixed it, even though I never see exception print statement.

    @try {
        [self addChild:node];
    }
    @catch (NSException *exception) {
        NSLog(@"Exception adding node :%@",[exception description]);
    }
    @finally {

    }
Alex Stone
  • 46,408
  • 55
  • 231
  • 407