-1
-(void)didMoveToView:(SKView *)view
{
    UITapGestureRecognizer* doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap:)];
    doubleTapGestureRecognizer.numberOfTapsRequired = 2;
    [self.view addGestureRecognizer:doubleTapGestureRecognizer];
}
-(void)doubleTap:(id)sender
{
    NSLog(@"double tap");
}

I am using this to add a gesture recognizer to my SKView. It works fine, double tap gets called when i double tap, but when i touch the screen and move my finger, app crashes with this error:

[UITapRecognizer name]: unrecognized selector sent to instance 0x1756c600

Why is this happenning? Im not calling any "name" selector on this recognizer.

I have this method:

#pragma mark - SKPhysicsContactDelegate

-(void)didBeginContact:(SKPhysicsContact *)contact
{
    if(![contact.bodyA.node.name isEqualToString:@"player"])
    {
        [contact.bodyA.node performSelector:@selector(removeFromParent) withObject:nil afterDelay:1];
    }
    if(![contact.bodyB.node.name isEqualToString:@"player"])
    {
        [contact.bodyB.node performSelector:@selector(removeFromParent) withObject:nil afterDelay:1];
    }

}

i noticed that if i comment this out, there is no such error, but then i replaced it with this:

-(void)didBeginContact:(SKPhysicsContact *)contact
{
    if(![contact.bodyA.node respondsToSelector:@selector(name)])
    {
        NSLog(@"%@ , %@ \n",contact.bodyA, contact.bodyA.node);
    }
    if(![contact.bodyB.node respondsToSelector:@selector(name)])
    {
        NSLog(@"%@ , %@",contact.bodyB, contact.bodyB.node);
    }
}

and there is nothing in debug log, just the same error. What is going on?

t0a0
  • 668
  • 1
  • 9
  • 18
  • What kind of class is contact.bodyA.node? you can find out like this -- NSLog(NSStringFromClass(@"%@", [contact.bodyA.node class])); – Joel Bell Nov 06 '14 at 00:10
  • @JoelBell they all are SKSpriteNodes :(, here is the full GameScene.m code. Something strange is going on. http://pastebin.com/dcrMNfZh . i noticed that the problem is actually in removeFromParent call. if if comment it out, no crash will occur. – t0a0 Nov 06 '14 at 12:27
  • Look at the exception stack trace (which you failed to provide). It tells you exactly where the failure occurred. (Obviously, somehow a UITapGuestureRecognizer address has gotten into a pointer for some other object.) – Hot Licks Nov 06 '14 at 17:51
  • @HotLicks i have no track, i have "all exceptions" breakpoint but when it crashes, the error is in main() – t0a0 Nov 07 '14 at 15:15

1 Answers1

1

turned out is was a duplicate of -> UITapGestureRecognizer causes app to crash

"I had the same issue in one of my SpriteKit Games, it is caused when you use gestures during transition between scenes, i solved it by setting gestureRecognizer.enable property (documentation) to NO before the transition." That answer helped

Community
  • 1
  • 1
t0a0
  • 668
  • 1
  • 9
  • 18