iphone - 断言失败 : (fixture->m_body == this)

标签 iphone c++ cocos2d-iphone box2d

我们有两个固定装置 vector (都是一个物体)

//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。

最佳答案

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

关于iphone - 断言失败 : (fixture->m_body == this),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9853993/

相关文章:

iphone - 如何使用 Phonegap 在屏幕底部显示原生 iPhone 标签栏?

iphone - 将对象添加到 NSMutableArray 不适用于 iPhone 应用程序

c++ - clang 错误 : c++/4. 8/bits/STL_iterator_base_types.h:227:29: 错误: 'iterator_category' 中没有名为 'std::iterator_traits<unsigned long>' 的类型

c++ - 在 C++11 中实现干净的 lambda 函数

c++ - 析构函数可以在 const 对象上调用非常量函数吗?

iphone - Apple 目前不接受使用此版本 SDK 构建的应用程序

iphone - 消耗品应用内购买

iphone - 当我将状态栏设置为隐藏或不隐藏时如何自动调整 ios View 的大小

iphone - 通过套接字下载多个文件与单个大文件并解压缩

iphone - UIGestureRecognizer不会旋转 Sprite - Cocos2d