libgdx/ashley

#iterator() cannot be used nested.

Closed this issue · 5 comments

fechy commented

Unfortunately, since the last release (1.7.1) I'm having this issue:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: #iterator() cannot be used nested.
    at com.badlogic.gdx.utils.Array$ArrayIterator.hasNext(Array.java:541)
    at com.badlogic.ashley.core.Engine.update(Engine.java:175)
    at com.kingmonkey.arkanoid.internal.CustomEngine.update(CustomEngine.java:25)
    at com.kingmonkey.arkanoid.game.controllers.EngineController.update(EngineController.java:41)
    at com.kingmonkey.arkanoid.screens.GameScreen.render(GameScreen.java:187)
    at com.kingmonkey.arkanoid.MainGame.render(MainGame.java:97)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:218)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:123)

This is because this change introduced in 1.7.1 on Engine.java:

-       for(int i=0; i<systems.size; i++){
 -          EntitySystem system = systems.get(i);
 +      for (EntitySystem system : systemManager.getSystems()) {

I'm not entirely sure how this happens, although I know it has to do with postRunnables. This happens when I do a heavy removal of entities and box2d bodies which are done on a postRunnable otherwise Box2d will issue a sigfaul.

I'll try to came up with a better explanation and possible a test case. In the mean time, I'll like you to consider to go back to the previous code if this is not entirely necessary.

This is because we re-use an internal iterator to avoid allocations. You can still instantiate a new iterator yourself. Will look into it anyway.

I'm also affected by this bug, but i'm currently using the Maven repo with gradle and i'm not sure the best way to update in this case? Is a new release expected to be out soon or should i consider switching to the git version?

I can make a patch release later this evening.

Thank you much!