Cocos2d game crashing shortly after CCCallFunc
**Situation:**<br />
Crashing shortly after a CCCallFunc. In short, we have a button. The button has a tag to identify it later. When the button is pressed, we run some actions to animate it, and when the animation is done, we CCCallFunc another method to transition to another scene. We crash shortly after the CCCallFunc. Source and errors below.


**Point Of Crash (in cocos2d source):**<br />

    // From CCActionInstant.m of cocos2d
    -(void) execute
    {
    	/*** EXC_BAD_ACCESS on line 287 of CCActionInstant.m ***/
    	[targetCallback_ performSelector:selector_];
    }
    @end



**Snapshot of Thread 1:**<br />
![Thread 1 stack][1]


**My Code:**<br />
Below is some source taken from MenuLayer.m (a simple menu to display a button). 

    // from MenuLayer.m
    // …
    
    @implementation MenuLayer
    
    -(id) init{
    
    	if((self=[super init])) {
    
    	/****** Create The Play Button (As a CCMenu) ********/
            CCSprite *playSprite = [CCSprite spriteWithFile:@"playbutton.png"];
               
            CCMenuItemSprite *playItem = [CCMenuItemSprite itemFromNormalSprite:playSprite selectedSprite:nil target:self selector:@selector(animateButton:)];
            playItem.tag = 3001;
            playItem.position = ccp(160.0f, 240.0f);
                  
            CCMenu *menu = [CCMenu menuWithItems:playItem, nil];
            menu.position = ccp(0.0f, 0.0f);
            [self addChild:menu z:0];
    
       	}
    }
    
    // ...
    
    - (void)animateButton:(id)sender{
        
        /*** Run an animation on the button and then call a function ***/
        id a1 = [CCScaleTo actionWithDuration:0.05 scale:1.25];
        id a2 = [CCScaleTo actionWithDuration:0.05 scale:1.0];
        id aDone = [CCCallFunc actionWithTarget:self selector:@selector(animationDone:)];
        [sender runAction:[CCSequence actions:a1,a2,aDone, nil]];
        
    }
    - (void)animationDone:(id)sender{
        
        /*** Identify button by tag ***/
        /*** Call appropriate method based on tag ***/
        if([(CCNode*)sender tag] == 3001){
            
    	/*** crashes around here (see CCActionInstant.m) ***/
            [self goGame:sender];
        }
    }
    
    -(void)goGame:(id)sender{
            
            /*** Switch to another scene ***/
     	CCScene *newScene = [CCScene node];
       	[newScene addChild:[StageSelectLayer node]];
    
            if ([[CCDirector sharedDirector] runningScene]) {
                [[CCDirector sharedDirector] replaceScene:newScene]];
            }else {
                [[CCDirector sharedDirector] runWithScene:newScene];
            }
    }


  [1]: http://i.stack.imgur.com/VRz5w.png
Cocos2d game crashing shortly after CCCallFunc
===

**Situation:**<br />
Crashing shortly after a CCCallFunc. In short, we have a button. The button has a tag to identify it later. When the button is pressed, we run some actions to animate it, and when the animation is done, we CCCallFunc another method to transition to another scene. We crash shortly after the CCCallFunc. Source and errors below.


**Point Of Crash (in cocos2d source):**<br />

    // From CCActionInstant.m of cocos2d
    -(void) execute
    {
    	/*** EXC_BAD_ACCESS on line 287 of CCActionInstant.m ***/
    	[targetCallback_ performSelector:selector_];
    }
    @end



**Snapshot of Thread 1:**<br />
![Thread 1 stack][1]


**My Code:**<br />
Below is some source taken from MenuLayer.m (a simple menu to display a button). 

    // from MenuLayer.m
    // …
    
    @implementation MenuLayer
    
    -(id) init{
    
    	if((self=[super init])) {
    
    	/****** Create The Play Button (As a CCMenu) ********/
            CCSprite *playSprite = [CCSprite spriteWithFile:@"playbutton.png"];
               
            CCMenuItemSprite *playItem = [CCMenuItemSprite itemFromNormalSprite:playSprite selectedSprite:nil target:self selector:@selector(animateButton:)];
            playItem.tag = 3001;
            playItem.position = ccp(160.0f, 240.0f);
                  
            CCMenu *menu = [CCMenu menuWithItems:playItem, nil];
            menu.position = ccp(0.0f, 0.0f);
            [self addChild:menu z:0];
    
       	}
    }
    
    // ...
    
    - (void)animateButton:(id)sender{
        
        /*** Run an animation on the button and then call a function ***/
        id a1 = [CCScaleTo actionWithDuration:0.05 scale:1.25];
        id a2 = [CCScaleTo actionWithDuration:0.05 scale:1.0];
        id aDone = [CCCallFunc actionWithTarget:self selector:@selector(animationDone:)];
        [sender runAction:[CCSequence actions:a1,a2,aDone, nil]];
        
    }
    - (void)animationDone:(id)sender{
        
        /*** Identify button by tag ***/
        /*** Call appropriate method based on tag ***/
        if([(CCNode*)sender tag] == 3001){
            
    	/*** crashes around here (see CCActionInstant.m) ***/
            [self goGame:sender];
        }
    }
    
    -(void)goGame:(id)sender{
            
            /*** Switch to another scene ***/
     	CCScene *newScene = [CCScene node];
       	[newScene addChild:[StageSelectLayer node]];
    
            if ([[CCDirector sharedDirector] runningScene]) {
                [[CCDirector sharedDirector] replaceScene:newScene]];
            }else {
                [[CCDirector sharedDirector] runWithScene:newScene];
            }
    }


  [1]: http://i.stack.imgur.com/VRz5w.png