Nifty throws IndexOutOfBoundsException

I occasionally get this error from nifty GUI. I have no idea why, and it does not seem to be replicable. I use nifty in a multithreaded application. Any idea how to trace the cause, or at least catch the exception?



[java]

5-ott-2011 21.12.07 com.jme3.app.Application handleError

GRAVE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.IndexOutOfBoundsException: Index: 2, Size: 0

at java.util.ArrayList.rangeCheck(ArrayList.java:571)

at java.util.ArrayList.get(ArrayList.java:349)

at com.jme3.niftygui.InputSystemJme.forwardEvents(InputSystemJme.java:167)

at de.lessvoid.nifty.Nifty.update(Nifty.java:227)

at com.jme3.niftygui.InputSystemJme.endInput(InputSystemJme.java:94)

at com.jme3.input.InputManager.processQueue(InputManager.java:773)

at com.jme3.input.InputManager.update(InputManager.java:837)

at com.jme3.app.Application.update(Application.java:567)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:235)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:144)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:218)

at java.lang.Thread.run(Thread.java:679)

[/java]

That error shouldn’t happen. Are you calling nifty.update() from the other thread?

1 Like

I’ve seen that happen, when removing things (like popups) when they’ve already been removed once.

One important thing to noe it that, at this time, Nifty is NOT thread safe. I’ve ran into stuff like this myself from time to time. All nifty calls need to be handled in the same thread, preferably your main thread.



That said, this is probably a hard one to catch without altering either the nifty source or the JME source, since the only classes in the stacktrace are Nifty and JME classes. So any catching and clean handling needs to be done there.



The problem most likely is due to something done very shortly before the error occured though. Something like removing elements could cause the problem, since all Nifyt elements are handled in arrays internally.

I confirm that removing calls to nifty.update() resolved the issue. Thanks momoko for pointing this out