Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndEngine GLES2- IndexOutOfBoundsException inside Entity.java line: 1402

I have following errors which I have no idea about:

06-08 19:59:54.367: E/AndroidRuntime(11629): FATAL EXCEPTION: UpdateThread
06-08 19:59:54.367: E/AndroidRuntime(11629): java.lang.IndexOutOfBoundsException: Invalid index 11, size is 0
06-08 19:59:54.367: E/AndroidRuntime(11629):    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
06-08 19:59:54.367: E/AndroidRuntime(11629):    at java.util.ArrayList.get(ArrayList.java:304)
06-08 19:59:54.367: E/AndroidRuntime(11629):    at org.andengine.entity.Entity.onManagedUpdate(Entity.java:1402)
06-08 19:59:54.367: E/AndroidRuntime(11629):    at org.andengine.entity.scene.Scene.onManagedUpdate(Scene.java:284)
06-08 19:59:54.367: E/AndroidRuntime(11629):    at org.andengine.entity.Entity.onUpdate(Entity.java:1167)
06-08 19:59:54.367: E/AndroidRuntime(11629):    at org.andengine.engine.Engine.onUpdateScene(Engine.java:591)
06-08 19:59:54.367: E/AndroidRuntime(11629):    at org.andengine.engine.Engine.onUpdate(Engine.java:586)
06-08 19:59:54.367: E/AndroidRuntime(11629):    at org.andengine.engine.Engine.onTickUpdate(Engine.java:548)
06-08 19:59:54.367: E/AndroidRuntime(11629):    at org.andengine.engine.Engine$UpdateThread.run(Engine.java:820)

I believe it's something related with the onManagedUpdate() inside a MoveModifier I used inside my code.

like image 467
Nafis Avatar asked Jun 08 '13 14:06

Nafis


1 Answers

This is almost always due to detaching entities in the wrong thread. Check for anywhere that you might be detaching entities in response to a user interaction, or in a Modifier callback, and wrap it in runOnUpdateThread. E.g.:

@Override
public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
    engine.runOnUpdateThread(new Runnable() {
        @Override
        public void run() {
            widget.detachSelf();
        }
    });
}
like image 87
simonp Avatar answered Oct 20 '22 10:10

simonp