AndEngine:GLThread中的致命异常:IndexOutOfBoundsException

时间:2012-08-15 10:02:54

标签: android andengine

我正在为我的AndEngine的BaseGameActivity编写一个自定义对话框窗口,有时,当对话框必须消失时,应用程序会因此错误而崩溃:

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 个答案:

答案 0 :(得分:9)

我发现当你试图在后台线程中分离子进程时可能会发生这种情况,因此每次你想要分离时都必须使用这段代码:

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