Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BACKSPACE on TextField crashes after TextField loses focus #207

Closed
LakeIshikawa opened this issue Aug 6, 2016 · 3 comments
Closed

BACKSPACE on TextField crashes after TextField loses focus #207

LakeIshikawa opened this issue Aug 6, 2016 · 3 comments
Labels

Comments

@LakeIshikawa
Copy link

There appears to be a problem with the TextField after it loses and re-gain focus, when backspace is pressed an exception is generated:

Exception in thread "LWJGL Application" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1931)
at com.kotcrab.vis.ui.widget.VisTextField$TextFieldClickListener.keyTyped(VisTextField.java:1206)

The "cursor" field looks to be bigger than the actual word in the textfield.

@kotcrab
Copy link
Owner

kotcrab commented Aug 6, 2016

What version of VisUI are you using, can you reproduce with latest 1.1.5? Please tell exact steps to reproduce this. This doesn't work:

  1. Open VisUI test app
  2. Click on text field with "textbox" text, placing cursor at text end
  3. Remove everything using backspace
  4. Click on some button to make text field lost focus
  5. Click on same text field again
  6. Press backspace, app doesn't crash

@kotcrab kotcrab added the ui label Aug 6, 2016
@Snehks
Copy link
Contributor

Snehks commented Aug 10, 2016

I have encountered the sam bug but the way to produce it is as follows.

  1. Type something on the field.
  2. Select all in the text field
  3. Now remove focus, i.e. click on some other UI element or a text box.
  4. Go back to the original text field and then click backspace.
    BOOM! Crashes.

Yes I am using version 1.1.5

Stack trace

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1931)
at com.kotcrab.vis.ui.widget.VisTextField$TextFieldClickListener.keyTyped(VisTextField.java:1206)
at com.badlogic.gdx.scenes.scene2d.InputListener.handle(InputListener.java:49)
at com.badlogic.gdx.scenes.scene2d.Actor.notify(Actor.java:181)
at com.badlogic.gdx.scenes.scene2d.Actor.fire(Actor.java:146)
at com.badlogic.gdx.scenes.scene2d.Stage.keyTyped(Stage.java:445)
at com.badlogic.gdx.backends.lwjgl.LwjglInput.processEvents(LwjglInput.java:318)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)

I looked into the code thoroughly and found out that when you click on a text field for regaining focus, it sets the "cursor" int value which should be equal to length of text but when we click it is somehow changing cursor value to text length + 1. When we use tab to change focus, then that works fine.

protected void setCursorPosition (float x, float y) {
lastBlink = 0;
cursorOn = false;
cursor = letterUnderCursor(x); //This is the culprit I guess.
}

@kotcrab kotcrab added the bug label Aug 11, 2016
@kotcrab
Copy link
Owner

kotcrab commented Aug 11, 2016

Thanks for reproduction steps @Snehks. For some reason I could only reproduce when using LWJGL backend. I fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants