【问题标题】:Assertion failed: (fixture->m_body == this)断言失败:(fixture->m_body == this)
【发布时间】:2012-03-24 17:44:53
【问题描述】:

我们有两个固定装置向量(都是一个主体)

//Create and add fixtures to vector1 and vector2
b2PolygonShape shape1;
shape1.SetAsEdge(from1,to1);
vector1.push_back( body1->CreateFixture(&shape1,0) );

b2PolygonShape shape2;
shape2.SetAsEdge(from2,to2);
vector2.push_back( body2->CreateFixture(&shape2,0) );

当case event1时,我们销毁vector1中的第一个fixture。

body1->DestroyFixture( vector1[0] ); //destroy first fixture1
vector1.erase( vector1.begin() ); //remove from vector1

当case event2时,我们销毁vector2中的第一个fixture。

body2->DestroyFixture( vector2[0] ); //destroy first fixture2
vector2.erase( vector2.begin() ); //remove from vector2

问题: 有时,当我们 DestroyFixture(...) 时,我们会得到“Assertion failed: (fixture->m_body == this)

我查了一下,我知道vector1可以有一些fixture2,或者vector2有fixture1。为什么会这样? 我只将fixture1 添加到vector1,将fixture2 仅添加到vector2。

【问题讨论】:

    标签: iphone c++ cocos2d-iphone box2d


    【解决方案1】:

    如果您在碰撞回调函数中这样做,请不要这样做。 Box2D 禁止在碰撞事件期间移除物体/夹具。相反,标记主体以便稍后进行碰撞后处理,例如在下一个更新方法调用中。

    【讨论】:

      猜你喜欢
      • 2012-08-29
      • 2011-05-27
      • 2021-03-16
      • 2010-09-26
      • 2018-11-09
      • 2021-01-20
      • 2014-06-10
      • 2014-02-10
      相关资源
      最近更新 更多