AndEngine: Fatal exception in GLThread: IndexOutOfBoundsException

允我心安 提交于 2019-12-08 11:20:03

问题


I'm writing a custom dialog window for my AndEngine's BaseGameActivity and sometimes, when dialog have to dissapear, app crashes with this error:

08-15 09:49:16.193: ERROR/AndroidRuntime(1572): FATAL EXCEPTION: GLThread
        java.lang.IndexOutOfBoundsException: Invalid index 3, size is 3
        at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
        at java.util.ArrayList.get(ArrayList.java:304)
        at org.anddev.andengine.entity.Entity.onManagedDrawChildren(Entity.java:1008)
        at org.anddev.andengine.entity.Entity.onDrawChildren(Entity.java:1000)
        at org.anddev.andengine.entity.Entity.onManagedDraw(Entity.java:993)
        at org.anddev.andengine.entity.scene.Scene.onManagedDraw(Scene.java:233)
        at org.anddev.andengine.entity.Entity.onDraw(Entity.java:875)
        at org.anddev.andengine.engine.Engine.onDrawScene(Engine.java:517)
        at org.anddev.andengine.engine.Engine.onDrawFrame(Engine.java:509)
        at org.anddev.andengine.opengl.view.RenderSurfaceView$Renderer.onDrawFrame(RenderSurfaceView.java:154)
        at org.anddev.andengine.opengl.view.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:617)
        at org.anddev.andengine.opengl.view.GLSurfaceView$GLThread.run(GLSurfaceView.java:549)

回答1:


I have found that it may happen when you trying to detach child in a background thread, so you have to use this code everytime you want to detach something:

activity.runOnUpdateThread(new Runnable() {
    @Override
    public void run() {
        scene.detachChild(child);
    }
});


来源:https://stackoverflow.com/questions/11967400/andengine-fatal-exception-in-glthread-indexoutofboundsexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!