0
votes

I'm building a fairly simple game in SpriteKit. This is my first experience with SpriteKit and so far it has gone smoothly. I have gotten to the point now that I want to present a new SKScene when the player completes the game. I'm getting a Bad Access crash that I can't seem to diagnose.

I think I am presenting the scene correctly:

UnlockRockets *scene = [[UnlockRockets alloc] initWithSize:self.scene.size];
[self.view presentScene:scene];

Every time I get the following error on the presentScene: line - Thread 1: EXC_BAD_ACCESS (code=1, address = 0x10)

Looking at the thread trace it appears the crash might be originating at [SKNode isPaused]

Any advice would be great, I'm completely lost on this one.

2
My guess is that your problem is not how you're presenting your SKScene, but where. What method calls that code? - B.R.W.
I'm calling it in the didBeginContact function, is that not the best place to call it from? - Tyler Payne
Just making sure you got it right: that UnlockRockets scene is supposed to be some other screen in your game, right? If that's the case, then it should work. Maybe you have something wrong in the UnlockRockets scene. - B.R.W.
Try this: SKScene *scene = [[UnlockRockets alloc] initWithSize:self.size]; - sangony
Tried that, still no luck unfortunately. - Tyler Payne

2 Answers

0
votes

i think problem in your initWithSize method inside UnlockRockets class

0
votes

I have had the same issue with SKView present scene, even when scene was absolutely new without any configurations. So I solved it by using this.

    myScene *newScene = [myScene sceneWithSize:size];
    newScene.scaleMode = SKSceneScaleModeResizeFill;
    SKView *currentskView = (SKView*)  self.scene.view;
    SKScene *currentScene = (SKScene*) self.scene;
    [currentScene removeAllChildren];
    [currentScene removeFromParent];
    [currentskView presentScene:newScene];

also I've noticed that if declare strong reference for the scene - it's works in the way you did, but in that case scene live in memory even if it's invisible, and xCode notifies that there are memory warnings.