Иногда, примерно один раз из 20 попыток, игра вылетала.
Это не имеет смысла для меня. После первого запуска я пытался воспроизвести ошибку около 500 раз. Но без успеха. После перезапуска игры игра вылетела после 12-й попытки. Это влияет только на Windows. Я не мог воспроизвести ошибку на 2 разных телефонах Android даже после прибл. 500 попыток.
Я искал подобные ошибки более 8 часов, но они не подошли близко к моей проблеме и не помогли мне.
У меня есть System.out .print везде и через 1 ч обнаружил, что игра вылетает из-за следующей строки: body = world.createBody (bdef);
Я перепробовал все предложенные решения, добавил безопасность везде, где выписки, и попробовал все мыслимые предложения от Inte rnet (что вы можете увидеть в коде ниже) Ничего не помогло.
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)
I Я очень благодарен за любую идею.