有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java演员。setx=致命异常:GLThread 2967

我真的为这个有趣的问题感到毛骨悚然。我正在做我的加载屏幕。smallBox将根据asset manager加载百分比向右移动。当我尝试为smallBox设置x()时,收到了“致命异常:GLThread 2967”。我尝试了resize(),但没有成功,同样的错误。我不确定哪里出了错

这是我的密码:

public class LoadingScreen extends AbstractScreen {

private Image bigBox, smallBox;
private Stage stage;
float loadingPercent=0f;
private SpriteBatch batch;
private Texture loadingTexture;

public LoadingScreen(game game) {
    super(game);

    // load asset here
    Gdx.app.log("gamelog", "assetManager.load()");
    game.assetManager.load("img/loading.pack", TextureAtlas.class);
    game.assetManager.load("img/splash.pack", TextureAtlas.class);
}

@Override
public void show() {
    stage = new Stage();

    batch = new SpriteBatch();
    loadingTexture = new Texture(Gdx.files.internal("img/loadingTexture.png"));
    loadingTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    TextureRegion bigBoxTr = new TextureRegion(loadingTexture, 0, 0, 800, 480);
    TextureRegion smallBoxTr = new TextureRegion(loadingTexture, 0, 790, 800, 110);

    Image bigBox = new Image(bigBoxTr);
    Image smallBox = new Image(smallBoxTr);

    smallBox.setX(-800);
    smallBox.setY(160);

    bigBox.setX(0);
    bigBox.setY(0);

    stage.addActor(bigBox);
    stage.addActor(smallBox);
}

@Override
public void render(float delta) {
    // Clear the screen
    Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    loadingPercent = Interpolation.linear.apply(loadingPercent, game.assetManager.getProgress(), 0.1f);
    Gdx.app.log("gamelog", "LoadingScreen: =" + (-800+(int)(loadingPercent*800*2)) + " getProgress" + game.assetManager.getProgress());

    smallBox.setX(-800+(int)(loadingPercent*800*2)); //<------ problem point
    smallBox.invalidate();

    if (game.assetManager.update()) {
        Gdx.app.log("gamelog", "LoadingScreen: before calling SplashScreen =" + (-800+(int)(loadingPercent*800*2)) + " getProgress" + game.assetManager.getProgress());
        game.setScreen(new SplashScreen(game));
    }

    stage.act(delta);
    stage.draw();

}

LogCat上的错误日志

11-01 22:08:54.308: I/awesomegame(24701): LoadingScreen: =-800 getProgress0.0
11-01 22:08:54.318: D/memalloc(24701): /dev/pmem: Unmapping buffer base:0x51f68000 size:10297344 offset:9527296
11-01 22:08:54.328: W/dalvikvm(24701): threadid=11: thread exiting with uncaught exception (group=0x40c2ca68)
11-01 22:08:54.328: E/AndroidRuntime(24701): FATAL EXCEPTION: GLThread 2967
11-01 22:08:54.328: E/AndroidRuntime(24701): java.lang.NullPointerException
11-01 22:08:54.328: E/AndroidRuntime(24701):    at com.example.awesomegame.screens.LoadingScreen.render(LoadingScreen.java:128)
11-01 22:08:54.328: E/AndroidRuntime(24701):    at com.badlogic.gdx.Game.render(Game.java:46)
11-01 22:08:54.328: E/AndroidRuntime(24701):    at com.example.awesomegame.somegame.render(somegame.java:25)
11-01 22:08:54.328: E/AndroidRuntime(24701):    at com.badlogic.gdx.backends.安卓.AndroidGraphics.onDrawFrame(AndroidGraphics.java:487)
11-01 22:08:54.328: E/AndroidRuntime(24701):    at 安卓.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1463)
11-01 22:08:54.328: E/AndroidRuntime(24701):    at 安卓.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1217)

但是,当我注释掉行“smallBox.setX(-800+(int)(loadingPercent*800*2));//<;----问题点”时,bigBox显示正确。然而,根据LogCat(当line注释掉时),我认为是float/int问题:

11-01 22:03:29.261: I/awesomegame(24283): LoadingScreen: =-800 getProgress0.0
11-01 22:03:29.301: D/memalloc(24283): /dev/pmem: Mapped buffer base:0x52e94000 size:4255744 offset:3485696 fd:67
11-01 22:03:29.301: I/awesomegame(24283): LoadingScreen: =-800 getProgress0.0
11-01 22:03:29.311: D/memalloc(24283): /dev/pmem: Mapped buffer base:0x533c7000 size:5025792 offset:4255744 fd:70
11-01 22:03:29.321: I/awesomegame(24283): LoadingScreen: =-800 getProgress0.0
11-01 22:03:29.331: I/awesomegame(24283): LoadingScreen: =-800 getProgress0.0
...
11-01 22:03:30.362: I/awesomegame(24283): LoadingScreen: =-38 getProgress0.5
11-01 22:03:30.512: I/awesomegame(24283): LoadingScreen: =-34 getProgress0.5
11-01 22:03:30.532: I/awesomegame(24283): LoadingScreen: =-31 getProgress0.5
11-01 22:03:30.532: I/awesomegame(24283): LoadingScreen: =-28 getProgress0.5
11-01 22:03:30.552: I/awesomegame(24283): LoadingScreen: =-25 getProgress0.5
11-01 22:03:30.572: I/awesomegame(24283): LoadingScreen: =-23 getProgress0.5
11-01 22:03:30.572: I/awesomegame(24283): LoadingScreen: =-21 getProgress0.5
11-01 22:03:30.592: I/awesomegame(24283): LoadingScreen: =-19 getProgress0.5
11-01 22:03:30.612: I/awesomegame(24283): LoadingScreen: =-17 getProgress0.5
11-01 22:03:30.612: I/awesomegame(24283): LoadingScreen: =-15 getProgress0.5
11-01 22:03:30.672: I/awesomegame(24283): LoadingScreen: =-14 getProgress0.5
11-01 22:03:30.692: I/awesomegame(24283): LoadingScreen: =-12 getProgress0.5
11-01 22:03:30.872: I/awesomegame(24283): LoadingScreen: =-11 getProgress0.5
11-01 22:03:30.882: I/awesomegame(24283): LoadingScreen: before calling SplashScreen =-11 getProgress1.0

看来工作公式是正确的。我已经被困在这个问题上好几天了,不知道在哪里以及如何解决它

非常感谢,非常感谢您的帮助

问候 齐伊


共 (1) 个答案

  1. # 1 楼答案

    我找到了问题的根源。在跟踪每个步骤之后,似乎smallbox被放置在LoadingScreen和AbstractScreen之间。解决办法是加上“这个”作为smallbox的前缀

    不管怎样,谢谢你的帮助,@noone