我world.step(timeStep, iterations, iterations)
在一个线程中调用,Screen.render()
其中是另一个线程,这是:
MyBox2DDebugRenderer.render(world, cam.combined);
一段时间后,我会得到
FATAL EXCEPTION: GLThread 2328
java.lang.IndexOutOfBoundsException: Invalid index 7, size is 7
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
at java.util.ArrayList.get(ArrayList.java:304)
at com.kingx.spacejourney.MyBox2DDebugRenderer.renderBodies(MyBox2DDebugRenderer.java:132)
at com.kingx.spacejourney.MyBox2DDebugRenderer.render(MyBox2DDebugRenderer.java:74)
at com.kingx.spacejourney.Universe.render(Universe.java:85)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:449)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
MyBox2DDebugRenderer.java
130 int len = world.getContactList().size();
131 for (int i = 0; i < len; i++)
132 drawContact(world.getContactList().get(i));
因此,在渲染时,box2d 世界正在发生变化。你有一些想法如何同步这个吗?我应该把它放在一个线程中吗?