Yuvals
Yuvals

Reputation: 3266

How to handle a call from removed scene in SpriteKit?

I am working on a SpriteKit game and I am facing the following issue: I have PlayerSelection Scene and a Game Scene.

On PlayerSelection I use the following code:

- (void)didMoveToView:(SKView *)view {
    UIPanGestureRecognizer *gestureRecognizer = 
    [[UIPanGestureRecognizer alloc] initWithTarget:self
                                            action:@selector(handlePanFrom:)];

    [[self view] addGestureRecognizer:gestureRecognizer];
}

Once I leave the selection scene to the game scene the player, and start playing sometimes (but not always) get the following error and crash:

[PlayerSelectionScene handlePanFrom:]: message sent to 
                                       deallocated instance 0x15d01bc0

How is this possible that this message is called? I use this to navigate between scenes:

SKScene * scene = [[GameScene alloc] initWithSize:self.size];

[self.view presentScene:scene transition:transition];

Upvotes: 0

Views: 50

Answers (1)

Yuvals
Yuvals

Reputation: 3266

My bad - had to remove the UIPanGestureRecognizer in willMoveFromView

Upvotes: 1

Related Questions