繁体   English   中英

LibGDX 项目重启后才崩溃

[英]LibGDX Project crashes only after restarting

有时,大约每 20 次尝试,游戏就会崩溃。

这对我来说没有意义。 第一次启动后,我尝试重现错误大约 500 次。 但没有成功。 重新开始游戏后,游戏在第 12 次尝试后崩溃。 这只影响 Windows。 即使在大约 2 部不同的 Android 手机上,我也无法重现该错误。 500 次尝试。

我一直在寻找类似的错误超过 8 小时,但它们并没有接近我的问题,也没有帮助我。

我到处都有 System.out.print 指令,并在 1 小时后发现游戏由于以下行而崩溃: body = world.createBody(bdef);

我尝试了所有建议的解决方案,增加了安全性 if 语句无处不在,并尝试了来自 Internet 的所有可能的建议(您可以在下面的代码中看到)没有任何帮助。

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());

错误和日志

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)

我非常感谢任何想法。

有时,大约每 20 次尝试,游戏就会崩溃。

这对我来说没有意义。 第一次启动后,我尝试重现错误大约 500 次。 但没有成功。 重新开始游戏后,游戏在第 12 次尝试后崩溃。 这只影响 Windows。 即使在大约 2 部不同的 Android 手机上,我也无法重现该错误。 500 次尝试。

我一直在寻找类似的错误超过 8 小时,但它们并没有接近我的问题,也没有帮助我。

我到处都有 System.out.print 指令,并在 1 小时后发现游戏由于以下行而崩溃: body = world.createBody(bdef);

我尝试了所有建议的解决方案,增加了安全性 if 语句无处不在,并尝试了来自 Internet 的所有可能的建议(您可以在下面的代码中看到)没有任何帮助。

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());

错误和日志

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)

我非常感谢任何想法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM