为什么我删除b2body失败啊!!?

当我在BeginContact里面执行删除b2body的时候出现了错误:


void b2World::DestroyBody(b2Body* b)
{
    b2Assert(m_bodyCount > 0);
    b2Assert(IsLocked() == false);     //就是在这里出错,xcode的终端信息是:thread1 : signal SIGABRT
    if (IsLocked())
    {
        return;
    }


这个是碰撞的代码(我在里面加了网格动画,可能有错,但是注释了之后也不能删除原来的b2body和sprite):


void HelloWorld::BeginContact(b2Contact *contact){
    
    b2Body *bA = contact->GetFixtureA()->GetBody();
    b2Body *bB = contact->GetFixtureB()->GetBody();
    
    Sprite *sA = (Sprite*)bA->GetUserData();
    Sprite *sB = (Sprite*)bB->GetUserData();
    
    if((sA->getName()=="target" && sB->getName()=="projectile") ||
       (sB->getName()=="projectile" && sB->getName()=="target")){
        
        auto *sATexture = sA->getTexture();
        auto sSTextureRect = sA->getTextureRect();
        auto *_sA = Sprite::createWithTexture(sATexture,sSTextureRect);
        
        auto nodeGrid = NodeGrid::create();
        nodeGrid->addChild(_sA);
        this->addChild(nodeGrid);
        ActionInterval *disappearAction = ShatteredTiles3D::create(0.5, Size(10, 10), 4, false);
        CallFunc *disappearDone = CallFunc::create((){
            
            nodeGrid->removeFromParent();
            return ;
        });
        nodeGrid->runAction(Sequence::create(disappearAction, disappearDone, NULL) );
        
        phyWorld->DestroyBody(bA);
        phyWorld->DestroyBody(bB);
        
        sA->removeFromParent();
        sB->removeFromParent();
        
    }
    
}

这到底是怎么回事啊!!!
急死了

不好在这里删除吧,你应该把body缓存起来,在别的地方删除,试试看,我也没怎么搞过b2d

正解啊正解!!!我新写了一个方法,碰撞的时候缓存要删除body和sprite,在update()里面删除。。。果然成功了!太感谢了,又长见识了