0

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.

  • My guess is that your problem is not **how** you're presenting your `SKScene`, but **where**. What method calls that code? – B.R.W. Aug 12 '14 at 13:08
  • I'm calling it in the didBeginContact function, is that not the best place to call it from? – Tyler Payne Aug 12 '14 at 13:31
  • 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. Aug 12 '14 at 13:37
  • Try this: SKScene *scene = [[UnlockRockets alloc] initWithSize:self.size]; – sangony Aug 12 '14 at 17:14
  • Tried that, still no luck unfortunately. – Tyler Payne Aug 13 '14 at 06:59

2 Answers2

0

i think problem in your initWithSize method inside UnlockRockets class

dragoneye
  • 703
  • 6
  • 14
  • I've commented everything out of the initWithSize method other than setting the background color to check this. It still crashes. – Tyler Payne Aug 13 '14 at 06:59
0

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.

Den
  • 311
  • 2
  • 4