Java libGDX-Box2D断言失败
我正在使用libGDX,但得到一个Java libGDX-Box2D断言失败,java,libgdx,box2d,Java,Libgdx,Box2d,我正在使用libGDX,但得到一个断言失败来自box2D的错误: Assertion failed! Program: C:\Program Files\Java\jre1.8.0_31\bin\javaw.exe File: /var/lib/jenkins/workspace/libgdx/extensions/gdx-box2d/gdx-box2d/jni/Box2D/Collision/Shapes/b2PolygonShape.cpp, Line 158 Expression: f
断言失败代码>来自box2D的错误:
Assertion failed!
Program: C:\Program Files\Java\jre1.8.0_31\bin\javaw.exe
File: /var/lib/jenkins/workspace/libgdx/extensions/gdx-box2d/gdx-box2d/jni/Box2D/Collision/Shapes/b2PolygonShape.cpp, Line 158
Expression: false
查看第158行的数据:b2Asert(false)代码>,位于::Set
功能中
n = tempCount;
if (n < 3)
{
// Polygon is degenerate.
b2Assert(false);
SetAsBox(1.0f, 1.0f);
return;
}
n=tempCount;
if(n<3)
{
//多边形是退化的。
b2Assert(假);
设置框(1.0f,1.0f);
返回;
}
我发现这(很可能)源自一种调整对象形状大小的方法:
private void updateShape(CubeComponent cc) {
// Kill any existing shapes.
if (cc.fixture != null && cc.fixture.getBody() != null) {
cc.body.destroyFixture(cc.fixture);
cc.fixture = null;
}
// don't even think about making a non-existing shape. It's almost as
// bad as dividing by zero.
if (cc.scale <= 0) {
return;
}
// Make a fixture
FixtureDef fdef = new FixtureDef();
fdef.density = 0.1f;
fdef.friction = 0.2f;
fdef.restitution = 0.5f;
///////////////Most likely coming from here////////
// Create the shape.
PolygonShape shape = new PolygonShape();
shape.set(new float[] {
-cc.scale / 2f, -cc.scale / 2f, -cc.scale / 2f, cc.scale / 2f,
cc.scale / 2f, -cc.scale / 2f, cc.scale / 2f, cc.scale / 2f
});
fdef.shape = shape;
///////////////Most likely coming from here////////
// Create the fixture.
cc.fixture = cc.body.createFixture(fdef);
// dispose of the bad shape.
shape.dispose();
}
private void updateShape(CubeComponent cc){
//杀死任何现有的形状。
if(cc.fixture!=null&&cc.fixture.getBody()!=null){
cc.阀体固定装置(cc.固定装置);
cc.fixture=null;
}
//甚至不要考虑制作一个不存在的形状。它几乎是一样的
//坏得像被零除一样。
如果(cc.scale我发现尺寸非常接近0的形状,例如0.000001,将被视为0
该修复程序将更改以下内容:
if (cc.scale <= 0) {
return;
}
if(cc.scale尝试按逆时针方向重新排列形状定义中的顶点
if (cc.scale < 0.001f) {
return;
}