Mein Spiel stürzt mit dieser Nachricht:Libgdx Box2D occassional Absturz auf createBody
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000066bcbd0d, pid=13948, tid=12700
# [...]
#
# Problematic frame:
# C [gdx-box2d64.dll+0xbd0d]
Von Protokolldatei:
Vollprotokoll: http://pastebin.com/QjY3msYS
Von allen anderen Beiträgen mit ähnlichen Abstürzen Es ist wahrscheinlich eine Weltmodifikation, wenn es nicht passieren sollte. Der Absturz tritt bei der Erstellung neuer Lebensmittel-Objekte:
// generateFood() - called during World.update
for (int i = 0; i < count; i++) {
float x = minX + (float) Math.random() * (maxX - minX);
float y = minY + (float) Math.random() * (maxY - minY);
Gdx.app.debug("World", "Generating food piece "+i);
this.foods.add(new Food(this, x, y, animateGrowth, this.renderable));
}
in den Lebensmittel Konstruktor:
// in Food(...) constructor
BodyDef bodyDef = new BodyDef(); //TODO: set to sleep on init?
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.position.set(x, y);
bodyDef.linearDamping = 0.5f;
bodyDef.angularDamping = 1f;
Gdx.app.debug("Food", "Init body with " + bodyDef + " at " + x + "," + y);
foodBody = world.box2dWorld.createBody(bodyDef); // <== HERE IS WHERE THE CRASH HAPPENS
CircleShape shape = new CircleShape();
shape.setRadius(getSizeFromEnergy());
fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
fixtureDef.density = 0.5f;
fixtureDef.friction = 0.4f;
fixtureDef.restitution = 0.2f;
fixture = foodBody.createFixture(fixtureDef);
fixture.setUserData(this);
shape.dispose();
Aber es kommt nur gelegentlich, manchmal nach Minuten Gameplay (wenn der generateFood Code erfolgreich ausgeführt wurde Hunderte Male). Also dachte ich, der Absturz muss etwas damit zu tun haben, was mit der Welt vor der Lebensmittelgeneration passiert. Also begann ich damit und Code zu deaktivieren, bis ich herausgefunden habe, dass der Absturz passiert nur, wenn nach der Zerstörung von box2d Körper meiner Zellobjekte:
public void update() { // Cell.update - called during World.update
if (this.energy <= 0) {
world.cells.remove(this);
Vector2 pos = cellBody.getPosition();
Gdx.app.debug("Cell", "Destroying " + cellBody+" at "+pos.x+","+pos.y);
world.box2dWorld.destroyBody(cellBody); // -> Without this line, the crashes don't happen!
return;
}
}
Hier ist das Protokoll:
World: Generating food piece 99
Food: Init body with [email protected] at -28.201607,-56.101532
World: Removing cell: [email protected]
Cell: Destroying [email protected] at -51.92446,-56.464954
World: Removing cell: [email protected]
Cell: Destroying [email protected] at -51.92446,-56.464954
World: Generating 100 new food pieces
World: Generating food piece 0
Food: Init body with [email protected] at 14.653984,96.249084
[...]
World: Generating food piece 21
Food: Init body with [email protected] at -15.35305,13.934067
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000066bcbd0d, pid=9792, tid=13288
#