当我在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();
}
}
这到底是怎么回事啊!!!
急死了