I've been having problems with CCMenuItem and its timing with CCCallFunc.
Basically I'm getting 'EXC_BAD_ACCESS'
@ this line of the CCMenuItem class
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
...
[selectedItem_ unselected]; // EXC_BAD_ACCESS
[selectedItem_ activate];
...
}
It seems the menu item is deallocated before the touch ends. I'm using CCCallFunc to call a 'removeThisSprite' method that removes it from the parent
so the last action of the CCMenuItem sequence I call:
[CCCallFuncO actionWithTarget:self selector:@selector(removeThisSprite:) object: _currentButton]
The removeThisSprite method is like this:
CCMenuItemSprite2 *sender = nil;
sender.isEnabled = NO;
if ([_sender isKindOfClass:[CCMenuItemSprite class]]) {
sender = _sender;
[sender removeFromParentAndCleanup: YES];
}
This generally happens when the player 'spams' the screen with taps, but doesn't happen unless the taps are rapid. Which is likely to occur with a game I'm making. I'm guessing there's some sort of timing issue going on with players pressing the button too fast.
You can always try and delay the removal of the menu item: