title: iphone cocos2d CCSprite EXC_BAD_ACCESS
body: <p>Friends i am new to cocos2d programming and Mac in general! </p>
  
  <p>I have noticed this EXC_BAD_ACCESS errors ruining most of my time... Take the following snippet of code from the <a href="http://geekanddad.wordpress.com/2010/06/22/enemies-and-combat-how-to-make-a-tile-based-game-with-cocos2d-part-3/" rel="nofollow noreferrer">Geek &amp; Dad's tutorial</a>...</p>
  
  <pre><code>-(void) AddEnemyAtX:(int)x Y:(int)y {
      CCSprite *enemy1 = [CCSprite spriteWithFile:@"enemy1.png"];
      enemy1.position = ccp(x,y);
      [self addChild:enemy1];
      [self animateEnemy:enemy1];
      NSLog(@"%@", enemy1);
  }
  
  -(void) animateEnemy:(CCSprite *)enemy {
      ccTime actualDuration = .5;
      id actionMove = [CCMoveBy actionWithDuration:actualDuration
             position:ccpMult(ccpNormalize(ccpSub(_player.position,enemy.position)), 10)];
      id actionFinished = [CCCallFunc actionWithTarget:self
             selector:@selector(animateEnemyFinished:)];
          [enemy runAction:[CCSequence actions:actionMove,actionFinished,nil]];
  }
  
  -(void) animateEnemyFinished:(id)sender {
      CCSprite *enemy = (CCSprite *)sender;
      [self animateEnemy:enemy];
  }
  </code></pre>
  
  <p>here _player is a global variable and accessible everywhere, I call <code>AddEnemyAtX: Y:</code> and pass some coordinates. My problem is the first time the loop runs fine... But again when the control is passed from <code>animateEnemyFinished</code> to <code>animateEnemy</code> then the app crashes mentioning "EXC_BAD_ACCESS"!</p>
  
  <p>From what i figured out, the Sprite reference is not passed correctly! Help!</p>