title: Cocos2d-x: 0xC0000005: Access violation reading location 0xCDCDCDD1
body: <p>everyone:</p>
  
  <p>The problem is strange. I paste my code first.</p>
  
  <pre><code>void GameObjectsLayer::updateEnemy(float interval)
  {
      UNREFERENCED_PARAMETER(interval);
      Enemy *lpEnemy = new Enemy("enemy1.png", 1, 10, 8);
      lpEnemy-&gt;getSprite()-&gt;setAnchorPoint(CCPointZero);
          lpEnemy-&gt;setPosition(ccp(-30, 400));
      CCMoveTo *lpMoveAction = CCMoveTo::create(350.0f / ENEMY1_MOVE_SPEED, ccp(320, lpEnemy-&gt;getPosition().y));
      CCCallFuncND *lpCallback = CCCallFuncND::create(lpEnemy-&gt;getSprite(), callfuncND_selector(GameObjectsLayer::removeEnemy), lpEnemy);
      CCSequence *lpSeqActions = CCSequence::create(lpMoveAction, lpCallback, NULL);
      this-&gt;addChild(lpEnemy-&gt;getSprite(), 10);
      lpEnemy-&gt;getSprite()-&gt;runAction(lpSeqActions);
      // When I set the breakpoint here, the _vEnemies is valid and the application runs well.
      _vEnemies-&gt;push_back(lpEnemy);
  }
  
  void GameObjectsLayer::removeEnemy(CCNode *lpSender, void *lpParam)
  {
      Enemy *lpEnemy = (Enemy*)lpParam;
      lpEnemy-&gt;getSprite()-&gt;stopAllActions();
      this-&gt;removeChild(lpSender);
      // When access the _vEnemies variable here, the exception occurs at "_vEnemies-&gt;begin()"
      // I set a breakpoint here, the address of _vEnemies is invalid, but I set a breakpoint in the previous function, the _vEnemies has a valid address, what happened? I really can't comprehend the behavior. _vEnemies is the member variable of this class.
      std::vector&lt;Enemy*&gt;::iterator iter = _vEnemies-&gt;begin();
      while (iter != _vEnemies-&gt;end())
      {
          if (lpEnemy == *iter)
          {
              this-&gt;removeChild(lpEnemy-&gt;getSprite());
              //delete *iter;
              iter = _vEnemies-&gt;erase(iter);
              continue;
          }
          ++iter;
      }
      delete lpEnemy;
  }
  </code></pre>
  
  <p>these two methods are used in two CCSchedules, which is intialized in init() method, the codes are below:</p>
  
  <pre><code>bool GameObjectsLayer::init()
  {
      bool bRet = false;
      do
      {
          /* not important, omit them */
  
          this-&gt;schedule(schedule_selector(GameObjectsLayer::updateEnemy), 5.0f);
          this-&gt;schedule(schedule_selector(GameObjectsLayer::enemyShoot), 1.0f);
  
          scheduleUpdate();
  
          bRet = true;
      }
      while (0);
  
      return bRet;
  }
  </code></pre>
  
  <p>I got a head-ache. I don't know what happened. The version of my cocos2d-x is 2.1.5, and IDE is VS2012. Thanks for help..</p>