[英]LibGDX Box2D RayCast fatal error
我正在進行raycast,但是有一個大問題。 這是錯誤消息。
# # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x00007f2a67b5345b, pid=19347, tid=139820316944128 # # JRE version: OpenJDK Runtime Environment (7.0_79-b14) (build 1.7.0_79-b14) # Java VM: OpenJDK 64-Bit Server VM (24.79-b02 mixed mode linux-amd64 compressed oops) # Derivative: IcedTea 2.5.5 # Distribution: Custom build (Wed Apr 15 12:39:15 UTC 2015) # Problematic frame: # C [libgdx-box2d64.so+0x3a45b] void b2DynamicTree::RayCast<b2WorldRayCastWrapper>(b2WorldRayCastWrapper*, b2RayCastInput const&) const+0x3ab # # Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
您可以在這里查看日志文件http://paste.ubuntu.com/11287130/這是我的回調和splitObj。
private final RayCastCallback callback = new RayCastCallback() {
@Override
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
//We can just slice the field and field is ChainShape
if (fixture.getShape() instanceof ChainShape) {
Body body = fixture.getBody();
List<Vector2> pointVec = rayCastMap.get(body);
if (pointVec == null) {
pointVec = new ArrayList<Vector2>();
rayCastMap.put(body, pointVec);
}
if (!pointVec.isEmpty() && !pointVec.get(0).equals(point)) {
pointVec.add(point.cpy());
splitObj(body, pointVec);
} else {
pointVec.add(point.cpy());
}
}
return 1;
}
};
private void splitObj(Body sliceBody, List<Vector2> splitedPoints) {
Vector2 a = splitedPoints.get(0);
Vector2 b = splitedPoints.get(1);
Array<Vector2> shape1Vertices = new Array<Vector2>();
shape1Vertices.addAll(a, b);
Array<Vector2> shape2Vertices = new Array<Vector2>();
shape2Vertices.addAll(a, b);
for (Vector2 vec : field.getVertices()) {
float determinant = det(a, b, vec);
if (determinant > 0) {
if (!shape1Vertices.contains(vec, false))
shape1Vertices.add(vec);
} else if (determinant < 0) {
if (!shape2Vertices.contains(vec, false))
shape2Vertices.add(vec);
}
}
GeometryUtils.arrangeClockwise(shape1Vertices);
GeometryUtils.arrangeClockwise(shape2Vertices);
FloatArray shape1 = arrayToFloatArray(shape1Vertices);
FloatArray shape2 = arrayToFloatArray(shape2Vertices);
FloatArray newShape;
float shape1Area = calculateArea(shape1);
float shape2Area = calculateArea(shape2);
box2dWorld.destroyBody(sliceBody);
ball.box2dBall.setActive(false);
float splicedArea;
if (det(a, b, ball.getPosition()) > 0) {
splicedArea = shape2Area * 100 / (shape1Area + shape2Area);
newShape = shape1;
} else {
splicedArea = shape1Area * 100 / (shape1Area + shape2Area);
newShape = shape2;
}
field.setIsSliced(true);
// setting the properties of the two newly created shapes
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.StaticBody;
bodyDef.position.set(sliceBody.getPosition());
FixtureDef fixtureDef = new FixtureDef();
// creating the first shape
PolygonShape polygonShape = new PolygonShape();
polygonShape.set(newShape.toArray());
fixtureDef.shape = polygonShape;
sliceBody = box2dWorld.createBody(bodyDef);
sliceBody.createFixture(fixtureDef);
}
我想切片一個對象(ChainShape),並且有一個可以在該鏈形內移動的球。我監聽touchDown,touchDragged和touchUp進行輸入。
touchDown獲取線的第一點,touchDragged獲取線的第二點,touchUp像這樣調用raycast。
box2dWorld.rayCast(callback, p2, p1);
當我打電話時,有時會出現致命錯誤。我怎么了? 我能做什么?
通常,如果在使用SIGSEGV
時看到SIGSEGV
Java運行時環境錯誤,則與已損壞的身體/關節等的使用有關。
看一下您的代碼,在這里您破壞了一個屍體:
box2dWorld.destroyBody(sliceBody);
然后一些行,您嘗試再次使用已經被破壞的物體(!):
bodyDef.position.set(sliceBody.getPosition());
您不能再使用被破壞的屍體了! 僅在確定不再使用屍體后,才嘗試破壞屍體。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.