cocos2d 2.X的 碰撞检测(子弹碰到怪物,怪物消失) 我的代码老是内存错误
void HelloWorld::upadates(float dt)
{
    this->addpaomo();
       //循环敌人
    std::vector<CCSprite*>::iterator pos;
  
    for (pos=targets->begin();pos!=targets->end();pos++)
    {
        CCSprite *_targets=*pos;
        //获取敌人的矩阵
        CCRect _targetsrect=CCRectMake(_targets->getPosition().x-_targets->getContentSize().width/2, _targets->getPosition().y-_targets->getContentSize().height/2, _targets->getContentSize().width, _targets->getContentSize().height);
        
        //循环子弹
        std::vector<CCSprite*>::iterator pos1;
        for (pos1=zidan->begin();pos1!=zidan->end();pos1++)
        {
            CCSprite *_zidans=*pos1;
            //获取子弹的矩阵
            CCRect _zidansrect=CCRectMake(_zidans->getPosition().x-_zidans->getContentSize().width/2, _zidans->getPosition().y-_zidans->getContentSize().height/2, _zidans->getContentSize().width, _zidans->getContentSize().height);
            
            
            
            //检测碰撞子弹和敌人的碰撞
            if (CCRect::CCRectIntersectsRect(_targetsrect,_zidansrect))
            {
                
                //将受到碰撞的敌人 放入toDetory容器
                toDestroy->push_back(_targets);
              
                
            }
            
           
            
        }
        std::vector<CCSprite*>::iterator pos2;
        for (pos2=toDestroy->begin(); pos2!=toDestroy->end(); pos2++) {
            
            CCSprite *_detory=*pos2;
            
            this->removeChild(_detory,true);
            
            //运行以下代码崩溃(从targets容器中清除敌人)
            
            pos2=targets->erase(pos2);
            
            
            
            
            
            
        }
        
    }
    
    toDestroy->clear();
    
  
  
 
    
    
}