0
votes

I'm working on raycast, but I have a big problem. Here is the error message.

#
# 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

You can look the log file here http://paste.ubuntu.com/11287130/ Here is my callback and 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);
}

I want to slice an object(ChainShape) and there is a ball which can move around inside this chainshape.I listen touchDown , touchDragged and touchUp for input.

touchDown gets first point of the line for raycast , touchDragged gets second point of the line and touchUp is calling raycast like this one.

box2dWorld.rayCast(callback, p2, p1);

When I call that , sometimes it gives this fatal error.What is my problem? What can I do?

1

1 Answers

1
votes

Usually if you see a SIGSEGV Java Runtime Environment error while working with box2d then it is related to the usage of an already destroyed body / joint etc.

Take a look at your code here you destroy a body:

box2dWorld.destroyBody(sliceBody);

Then some lines later you try to use that already destroyed body again (!):

bodyDef.position.set(sliceBody.getPosition());

You cannot use destroyed bodies anymore! Try to destroy bodies only after you are sure you are not going to use them anymore.