0
\$\begingroup\$

I am getting this error on creating body in contactListener

com.patchnhack.gdx A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x58 in tid 4628 (GLThread 15500), pid 4583

I am creating a body in beginContact callback like this:

    ......
    public void beginContact(Contact contact) {
        .....
        Fixture fixA = contact.getFixtureA();
        Fixture fixB = contact.getFixtureB();

        If( fixA.getUserData()== "ground" || fixB.getUserData()== "ground")
            createBody(0,0);
        ....
        ....
    }

// createbody method in screen class
    public void createBody(float x, float y, float radius) {
        BodyDef def = new BodyDef();
        def.type = BodyDef.BodyType.DynamicBody;
        def.position.set(x ,y);
        def.fixedRotation = true;
        body = world.createBody(def);
        CircleShape shape = new CircleShape();
        shape.setRadius(radius);
        FixtureDef fdef = new FixtureDef();
        fdef.restitution = 0.5f;
        fdef.shape = shape;
        fdef.density = 2;
        body.createFixture(fdef).setUserData("chip");
    }

I know this is something due to async with render thread. Please tell me how can I resolve this or some better way to do this.

edit: I have even tried

Gdx.app.PostRunnble(new Runnable(){
..
})

But that works strangely and bodies keep populating and ultimately crashing the app.

\$\endgroup\$
0
\$\begingroup\$

It was my silly mistake that ContactListener was invoked again and again because the body was responsible for making contact under gravity and creating infinite loop ;P

I enclosed the createBody() code inside Gdx.app.postRunnable(new Runnable(){ .... } And check if contact has already been made by a flag.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Can you share a little information about how you avoided this infinite loop, so it can help other developers who get themselves into the same situation? \$\endgroup\$ – DMGregory Apr 16 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.