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?


5-ott-2011 21.12.07 handleError

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

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

at java.util.ArrayList.rangeCheck(

at java.util.ArrayList.get(

at com.jme3.niftygui.InputSystemJme.forwardEvents(

at de.lessvoid.nifty.Nifty.update(

at com.jme3.niftygui.InputSystemJme.endInput(

at com.jme3.input.InputManager.processQueue(

at com.jme3.input.InputManager.update(



at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(




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