libGDX:屏幕处置多次(IllegalArgumentException)

时间:2015-11-20 11:51:03

标签: java libgdx

我创建了Array<InputProcessor>();,我添加了stagethis(我的类实现了InputProcessor

public MyClass implements Screen, InputProcessor {
    private Stage stage;
    .....
    private InputMultiplexer inputMultiplexer;
    private Array<InputProcessor> arrayProcessor = new Array<InputProcessor>();

    @Override
    public void show() {
        .....

    arrayProcessor.add(this);
    arrayProcessor.add(stage);
    inputMultiplexer = new InputMultiplexer();
    inputMultiplexer.setProcessors(arrayProcessor);
    Gdx.input.setInputProcessor(inputMultiplexer);

    }

    .....

}

我首先调用了touchUp方法,删除了inputProcessor:

@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
    isTouchUp = true;
    return false;
}

render方法中:

@Override
public void render(float delta) {
    .....
    if(isTouchUp) {
       arrayProcessor.removeValue(this, true);
       isTouchUp = false;
    }
}

其次,我从touchUp actor的监听器调用了Image方法,该监听器添加了inputProcessor:

listener = new InputListener() {
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            return true;
        }
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
         arrayProcessor.clear();
         arrayProcessor.add(MyClass.this);
         arrayProcessor.add(stage);
        }
}
image.addListener(listener);

我重复删除和添加inputProcessor 3次。

到现在为止一切正常。

但是何时和我处理MyClass屏幕并设置新的Screen

((Game) Gdx.app.getApplicationListener()).dispose();
((Game) Gdx.app.getApplicationListener()).setScreen(new TestScreen());

MyClass处置了3次。

@Override
public void dispose() {
    System.out.println("MyClass diposed");
    stage.dispose();
    .....
}

然后输出显示为Exception

MyClass diposed
MyClass diposed
MyClass diposed
Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: buffer not allocated with newUnsafeByteBuffer or already disposed

我觉得我的代码中有一些微不足道的错误,我不知道为什么:),我试图找到它但无济于事。

任何人都可以帮助我?

0 个答案:

没有答案