Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Andengine中创建物理体时出现的奇怪错误_Java_Android_Andengine_Jbox2d - Fatal编程技术网

Java 在Andengine中创建物理体时出现的奇怪错误

Java 在Andengine中创建物理体时出现的奇怪错误,java,android,andengine,jbox2d,Java,Android,Andengine,Jbox2d,我试图通过这样的代码创建一个多边形物理体: final float halfWidth = pAreaShape.getWidthScaled() * 0.5f / PIXEL_TO_METER_RATIO_DEFAULT; final float halfHeight = pAreaShape.getHeightScaled() * 0.5f / PIXEL_TO_METER_RATIO_DEFAULT; final fl

我试图通过这样的代码创建一个多边形物理体:

        final float halfWidth = pAreaShape.getWidthScaled() * 0.5f / PIXEL_TO_METER_RATIO_DEFAULT;
        final float halfHeight = pAreaShape.getHeightScaled() * 0.5f / PIXEL_TO_METER_RATIO_DEFAULT;            
        final float centerX = 0;
        final float left = -halfWidth;
        final float right = halfWidth;
        final float top = -halfHeight + 9f / PIXEL_TO_METER_RATIO_DEFAULT;
        final float bottom = halfHeight;

        final PolygonShape shape1 = new PolygonShape();

        final Vector2[] vertices = {
                new Vector2(centerX, bottom),
                new Vector2(left+8f/PIXEL_TO_METER_RATIO_DEFAULT, bottom-19f/PIXEL_TO_METER_RATIO_DEFAULT),
                new Vector2(left+7f/PIXEL_TO_METER_RATIO_DEFAULT, bottom-23f/PIXEL_TO_METER_RATIO_DEFAULT),
                new Vector2(left+10f/PIXEL_TO_METER_RATIO_DEFAULT, top+14f/PIXEL_TO_METER_RATIO_DEFAULT),
                new Vector2(left+13f/PIXEL_TO_METER_RATIO_DEFAULT, top+8f/PIXEL_TO_METER_RATIO_DEFAULT),

                new Vector2(right-14f/PIXEL_TO_METER_RATIO_DEFAULT, top+8f/PIXEL_TO_METER_RATIO_DEFAULT),
                new Vector2(right-11f/PIXEL_TO_METER_RATIO_DEFAULT, top+14f/PIXEL_TO_METER_RATIO_DEFAULT),
                new Vector2(right-9f/PIXEL_TO_METER_RATIO_DEFAULT, bottom-23f/PIXEL_TO_METER_RATIO_DEFAULT),
                new Vector2(right-10f/PIXEL_TO_METER_RATIO_DEFAULT, bottom-19f/PIXEL_TO_METER_RATIO_DEFAULT)
        };

        Body body = PhysicsFactory.createPolygonBody(pPhysicsWorld, pAreaShape, vertices, pBodyType, pFixtureDef);
可变顶点包含此形状的顶点

它不工作——应用程序启动(显示黑屏和应用程序标题栏),然后退出,没有任何错误(没有崩溃对话框,LogCat中也没有错误)

但当我删除顶点数组中的一个元素时,效果很好


我做错了什么?

Box2D在多边形中最多有8个顶点,如果指定更多顶点,则断言将失败。我不确定Box2D和Engine使用的是什么版本,但试着制作一个循环或边缘形状

是的,你是对的。但我仍然想知道,为什么应用程序在没有任何错误报告的情况下崩溃。无论如何都要感谢,因为断言失败了,这通常会使进程崩溃。如果没有为本机构建启用断言,那么它可能会因为内存位置非法而失败。基本上,这可能是一次严重的碰撞