Doug Molineux
Doug Molineux

Reputation: 12431

iPad App Crashing with NSInvalidArgumentException

I am trying to make my first cocos2d, chipmunk ipad app

I set a "ball" sprite in my .h file like this:

 // HelloWorld Layer 
 @interface
 HelloWorld : CCLayer {     
    cpSpace  *space;
    CCSprite *ball;     
 }

and I am moving it like this (upon a touch):

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    for( UITouch *touch in touches ) {
        CGPoint location = [touch locationInView: [touch view]];

        location = [[CCDirector sharedDirector] convertToGL: location];         

        // Determine speed of the target
        int minDuration = 2.0;
        int maxDuration = 4.0;
        int rangeDuration = maxDuration - minDuration;
        int actualDuration = (arc4random() % rangeDuration) + minDuration;

        // Create the actions
        id actionMove = [CCMoveTo actionWithDuration:actualDuration 
                                            position:ccp(location.x, location.y)];
        id actionMoveDone = [CCCallFuncN actionWithTarget:self 
                                                 selector:@selector(spriteMoveFinished:)];
        [ball runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];

        [ball retain]; 
    }
}

When I run with the debugger I get this:

2011-06-29 20:44:04.121 ballgame[3499:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HelloWorld spriteMoveFinished:]: unrecognized selector sent to instance 0x605a3e0'

It appears to work for a couple touches and then it seems to crash, so perhaps its memory leak? Any suggestions or advice would really help, this is like my first app.

Cheers!

Upvotes: 0

Views: 222

Answers (3)

Peter DeWeese
Peter DeWeese

Reputation: 18333

Did you define a spriteMoveFinished: method? If not, define it. If it already is then your HelloWorld object probably hasn't been retained anywhere.

Upvotes: 2

Nick B
Nick B

Reputation: 1101

You are calling a method (spriteMoveFinished:) on your HelloWorld object that doesn't exist. Did you make a spriteMoveFinished: method?

'Unrecognized selector sent' = calling a method that isn't there.

Upvotes: 4

Rahul Vyas
Rahul Vyas

Reputation: 28720

Did you try debugging your app? Try NSZombie also according to your crash log one of your object is released and you called a function on that. Try NSZombieEnable in your environment flag.

Upvotes: 2

Related Questions