[Fixed]Nifty Text Field bug

If you type any amount of text into a text field, copy it by selecting then pressing c then paste at the end using v then it works once but a second time (not sure if its always on the second, press it a few times or hold it down and it definitely happens) causes a crash that completely kills the app:



[java]

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

java.lang.StringIndexOutOfBoundsException: String index out of range: 8

at java.lang.String.substring(String.java:1955)

at java.lang.String.subSequence(String.java:1993)

at de.lessvoid.nifty.controls.textfield.TextFieldLogic.filterAndInsert(TextFieldLogic.java:449)

at de.lessvoid.nifty.controls.textfield.TextFieldLogic.insert(TextFieldLogic.java:503)

at de.lessvoid.nifty.controls.textfield.TextFieldLogic.put(TextFieldLogic.java:489)

at de.lessvoid.nifty.controls.textfield.TextFieldControl.inputEvent(TextFieldControl.java:200)

at de.lessvoid.nifty.controls.NiftyInputControl.keyEvent(NiftyInputControl.java:54)

at de.lessvoid.nifty.elements.Element.keyEvent(Element.java:1777)

at de.lessvoid.nifty.controls.FocusHandler.keyEvent(FocusHandler.java:247)

at de.lessvoid.nifty.screen.Screen.keyEvent(Screen.java:434)

at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processKeyboardEvent(Nifty.java:1297)

at com.jme3.niftygui.InputSystemJme.onKeyEventQueued(InputSystemJme.java:193)

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

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

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

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

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

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

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

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

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

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

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

[/java]

Any difference if you paste rapidly or slowly?

No. First paste works, second crashes. Tried it in a few different places and with delays of several seconds between pastes as well.



Btw its all done with keyboard shortcuts.



Type “test”



Hold down shift, left arrow twice.

ctrl c

ctrl v



You now see test (as it overwrote itself)

ctrl v again

boom



You can even make it crash the first time by moving the cursor around before doing the first ctrl v.

The only text field I have is in a popup and pasting several times didn’t crash anything…



Is it possible you’ve got a bound key using c or v that is getting triggered? That could cause the crash. Maybe?

I don’t know if the popup would make a difference as mine aren’t in them. I am using latest nightly JME and latest nifty (built myself) so maybe its something that has only started with a more recent build…

Fixed in Nifty git with this commit.



If it looks like a Nifty bug - like in this case - don’t hesitate and create a new issue here: https://github.com/void256/nifty-gui/issues



Thanks :slight_smile:

1 Like

Thanks void :slight_smile:



I put it here first as there was a chance it was something in the JME input handling (although it did seem more likely it was internal to nifty).

1 Like

Just pulled and updated to the latest and I can confirm that it seems fixed, thanks Void :slight_smile: