12-30 12:19:56.210 18210-18256/com.example.SpriteTest E/AndroidRuntime﹕ FATAL EXCEPTION: UpdateThread
java.lang.IndexOutOfBoundsException: Invalid index 37, size is 37
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)
at org.anddev.andengine.entity.Entity.onManagedUpdate(Entity.java:854)
at org.anddev.andengine.entity.Entity.onUpdate(Entity.java:726)
at org.anddev.andengine.entity.Entity.onManagedUpdate(Entity.java:854)
at org.anddev.andengine.entity.scene.Scene.onManagedUpdate(Scene.java:288)
at org.anddev.andengine.entity.Entity.onUpdate(Entity.java:726)
at org.anddev.andengine.engine.Engine.onUpdateScene(Engine.java:478)
at org.anddev.andengine.engine.Engine.onUpdate(Engine.java:473)
at org.anddev.andengine.engine.Engine.onTickUpdate(Engine.java:449)
java.lang.IndexOutOfBoundsException: Invalid index 37, size is 37
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)
at org.anddev.andengine.entity.Entity.onManagedUpdate(Entity.java:854)
at org.anddev.andengine.entity.Entity.onUpdate(Entity.java:726)
at org.anddev.andengine.entity.Entity.onManagedUpdate(Entity.java:854)
at org.anddev.andengine.entity.scene.Scene.onManagedUpdate(Scene.java:288)
at org.anddev.andengine.entity.Entity.onUpdate(Entity.java:726)
at org.anddev.andengine.engine.Engine.onUpdateScene(Engine.java:478)
at org.anddev.andengine.engine.Engine.onUpdate(Engine.java:473)
at org.anddev.andengine.engine.Engine.onTickUpdate(Engine.java:449)
at org.anddev.andengine.engine.Engine$UpdateThread.run(Engine.java:673)
原因在于没有对引擎加锁的情况下进行了移除实体的操作。
解决办法:在将实体移除某场景之前先对引擎枷锁,操作完成后解锁
pScene.detachChild(this.mFaceToRemove);
this.mFaceToRemove.dispose();
this.mFaceToRemove = null;
engineLock.unlock();