Java LibGDX项目仅在重新启动后崩溃
有时,大约20次尝试中就有一次,游戏崩溃了 这对我来说毫无意义。在第一次启动后,我尝试复制错误大约500次。但是没有成功。重新启动游戏后,游戏在第12次尝试后崩溃。这只影响Windows。即使尝试了大约500次,我也无法在2部不同的Android手机上重现该错误 我一直在寻找类似的错误超过8个小时,但他们没有接近我的问题,也没有帮助我 我到处都有System.out.print说明,1小时后发现游戏因以下原因崩溃: body=world.createBodybdef 我尝试了所有建议的解决方案,在所有地方都添加了安全if语句,并尝试了互联网上的每一个可想象的建议——你可以在下面的代码中看到——没有任何帮助Java LibGDX项目仅在重新启动后崩溃,java,android,libgdx,Java,Android,Libgdx,有时,大约20次尝试中就有一次,游戏崩溃了 这对我来说毫无意义。在第一次启动后,我尝试复制错误大约500次。但是没有成功。重新启动游戏后,游戏在第12次尝试后崩溃。这只影响Windows。即使尝试了大约500次,我也无法在2部不同的Android手机上重现该错误 我一直在寻找类似的错误超过8个小时,但他们没有接近我的问题,也没有帮助我 我到处都有System.out.print说明,1小时后发现游戏因以下原因崩溃: body=world.createBodybdef 我尝试了所有建议的解决方案,
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);
}
}
}
错误和日志
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)
我非常感激任何一种想法。我自己解决了这个问题。如果你有这个问题,不要试图改变jre版本。Libgdx需要1.8 如果你有这个问题,我真的很抱歉,这个问题可能有很多原因。我在这里列出了一些: Body多次创建world.createBody或多次销毁world.destroyBody 随着世界的发展,可以创建或删除实体。步骤
在我的例子中,我错误地处理了一个对象。你检查了日志文件以了解更多信息吗?我检查了日志大约1个小时,检查了几乎每一行我不理解的内容,但在这里没有找到任何对我有帮助的内容。而且你还没有将日志的内容发布在这里,因此我们无法检查它,因此无法理解日志太长,无法在此处发布。这似乎是OpenJDK 9中修复的一个bug
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)