LibGDX Project crashes only after restarting

-3

Sometimes, about once in 20 attempts, the game crashed.

It doesn't make sense to me. After the first start I tried to reproduce the error about 500 times. But without success. After restarting the game, the game crashed after the 12th attempt. This only affects Windows. I could not reproduce the error on 2 different Android phones even after approx. 500 attempts.

I've been looking for similar errors for over 8 hours, but they didn't come close to my Problem and didn't help me.

I have System.out.print instructions everywhere and found after 1h that the game crashes due to the following line: body = world.createBody(bdef);

I tried all the proposed solutions, added security if Statements everywhere and tried every conceivable suggestion from the Internet (what you can see in the code below) Nothing helped.

public class Coins extends SpawnAble {

    private TextureRegion textureRegion[][];
    private Texture texture;
    private int framecount = 0;
    private int frame = 0;
    private int startcount;

    public Coins(Playscreen playscreen, float x, float y) {
        super(playscreen, x, y);

        texture = new Texture("spr_coin_strip4.png");
        textureRegion = TextureRegion.split(texture, 16, 16);

        setRegion(textureRegion[0][frame]);
        startcount = (int) (y * 100) / 16 * 10 - 64;
        System.out.println(startcount);
    }

    @Override
    public void defineSpawnAble() {
        BodyDef bdef = new BodyDef();
        bdef.type = BodyDef.BodyType.KinematicBody;
        System.out.println("Body Created Kinematic");
        bdef.position.set(getX() + getWidth() / 2, getY() + getHeight() / 2);
        System.out.println("set position "+world.isLocked());
        if (body == null) {
            body = world.createBody(bdef);
        }
        System.out.println("set crated");

        FixtureDef fdef = new FixtureDef();
        CircleShape shape = new CircleShape();
        shape.setRadius(6 / Statics.PPM);
        fdef.isSensor = true;
        fdef.shape = shape;
        fdef.filter.categoryBits = BIT_FILTER.SPAWNABLE_BIT;
        fdef.filter.maskBits = BIT_FILTER.PLAYER_BIT | BIT_FILTER.BRICK_BIT | BIT_FILTER.DEFAULT_BIT | BIT_FILTER.OBJEKT_BIT | BIT_FILTER.MOVING_BIT;
        body.createFixture(fdef).setUserData(this);
        System.out.println("set userdata");
    }

    @Override
    public void use() {
        System.out.println("spawnable used");
        playscreen.getPlayer().collectGem();
        if (!destroyed && !toDestroyed) {
            if (body != null) {
                destroy();
            }
        }
    }

    @Override
    public void update(float dt) {

        super.update(dt);

        if(!destroyed) {
            if (startcount >= 0) {
                startcount--;
            }

            if (!toDestroyed && !destroyed) {
                framecount++;
                if ((framecount % 15) == 0) {
                    frame++;
                    if (frame > 3) {
                        frame = 0;
                    }
                }
            }

            setRegion(textureRegion[0][frame]);
            setPosition(body.getPosition().x - getWidth() / 2, body.getPosition().y - getHeight() / 2);
        }
    }

    @Override
    public void draw(Batch batch) {
        if (startcount <= 0 && !destroyed) {
            super.draw(batch);
        }
    }
}
public class SpawnDef {

    public Vector2 position;
    public Class<?> type;

    public SpawnDef(Vector2 position, Class<?> type){
        this.position = position;
        this.type = type;
    }

}

public abstract class SpawnAble extends Sprite {

    protected Playscreen playscreen;
    protected World world;
    protected boolean toDestroyed;
    protected boolean destroyed;
    protected Body body;

    public SpawnAble(Playscreen playscreen, float x, float y){
        this.playscreen = playscreen;
        this.world = playscreen.getWorld();
        setPosition(x, y);
        setBounds(getX(), getY(), 16 / Statics.PPM, 16 / Statics.PPM);

        defineSpawnAble();

        toDestroyed = false;
        destroyed = false;
    }

    public void update(float dt){
        if (toDestroyed && !destroyed){
            destroyed = true;
            if (body != null) {
                world.destroyBody(body);
            }
        }
    }

    public void draw(Batch batch){
        if (!destroyed){
            super.draw(batch);
        }
    }

    public abstract void defineSpawnAble();
    public abstract void use();
    public void destroy(){
        toDestroyed = true;
    }

}

//Mainclass
public void spawn(SpawnDef sdef){
        tospawn.add(sdef); //Arraylist
    }

[...]

    public void handleSpawning(){
        if (!tospawn.isEmpty()){
            SpawnDef spawnDef = tospawn.get(tospawn.size()-1);
            if (spawnDef.type == Coins.class){
                System.out.println("spawning....");
                spawnAbles.add(new Coins(Playscreen.this, spawnDef.position.x, spawnDef.position.y)); //Arraylist
                System.out.println("spawned");
                tospawn.remove(tospawn.size()-1);
            }
        }
    }

[...]

 @Override
 public void render(float delta) {

 world.step(1 / 60f, 6,2);

 [...]

 handleSpawning();

 [...]

 for (SpawnAble spawnAble : spawnAbles){
            spawnAble.update(dt);
        }
 }

 [...]

 for (SpawnAble spawnAble : spawnAbles){
            spawnAble.draw(jumpAndRun.batch);
 }

 [...]

 System.out.println(""+spawnAbles.size() + "|" + tospawn.size());

Error and Log

spawned
spawnable update beginn
spawnable update ende
spawnable zeichnen beginn
spawnable zeichnen ende
2|1
world stepped
spawning....
Body Created Kinematic
set position false
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006e9cbbb1, pid=2292, tid=0x0000000000000b8c
#
# JRE version: OpenJDK Runtime Environment (8.0_212-b04) (build 1.8.0_212-release-1586-b04)
# Java VM: OpenJDK 64-Bit Server VM (25.212-b04 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [gdx-box2d64.dll+0xbbb1]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\flori\Desktop\JumpandRun\Game\hs_err_pid2292.log
#
# If you would like to submit a bug report, please visit:
#   
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
AL lib: (EE) alc_cleanup: 1 device not closed

Process finished with exit code 1


----------------------------------------------------------------------------

Log: https://pastebin.com/ep0NZnJQ (too long to post here)

I am very grateful for any kind of idea.

java
android
libgdx
asked on Stack Overflow Apr 29, 2020 by Florian Sprenger • edited Apr 29, 2020 by Florian Sprenger

1 Answer

0

I solved the problem by myself. If you have this Problem, dont try to change jre version. Libgdx need 1.8.

If you have this problem, I'm really sorry, this problem can have many reasons. I have listed a few here:

  • Bodys are created multiple times (world.createBody) or destroyed multiple times (world.destroyBody ())
  • You create or delete a Body as the world progresses (world.step)

In my case, I disposed an object incorrectly.

answered on Stack Overflow May 1, 2020 by Florian Sprenger

User contributions licensed under CC BY-SA 3.0