kotcrab/vis-ui

Crash when trying to select in VisTextArea when libGDX color marckup is enabled

Closed this issue · 3 comments

fgnm commented

VisTextArea and all its children (HighlightTextArea, ScrollableTextArea), crashes when color markup is enabled.

Stacktrace:

java.lang.IndexOutOfBoundsException: index can't be >= size: 1299 >= 1291
	at com.badlogic.gdx.utils.FloatArray.get(FloatArray.java:131)
	at com.kotcrab.vis.ui.widget.VisTextArea.drawSelection(VisTextArea.java:251)
	at com.kotcrab.vis.ui.widget.VisTextField.draw(VisTextField.java:350)
	at com.badlogic.gdx.scenes.scene2d.Group.drawChildren(Group.java:111)
	at com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.draw(ScrollPane.java:543)
	at com.badlogic.gdx.scenes.scene2d.Group.drawChildren(Group.java:124)
	at com.badlogic.gdx.scenes.scene2d.Group.draw(Group.java:58)
	at com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup.draw(WidgetGroup.java:170)
	at com.badlogic.gdx.scenes.scene2d.ui.Table.draw(Table.java:126)
	at com.badlogic.gdx.scenes.scene2d.Group.drawChildren(Group.java:111)
	at com.badlogic.gdx.scenes.scene2d.ui.Table.draw(Table.java:117)
	at com.badlogic.gdx.scenes.scene2d.ui.Window.draw(Window.java:253)
	at com.kotcrab.vis.ui.widget.VisWindow.draw(VisWindow.java:239)
	at com.badlogic.gdx.scenes.scene2d.Group.drawChildren(Group.java:111)
	at com.badlogic.gdx.scenes.scene2d.Group.draw(Group.java:58)
	at com.badlogic.gdx.scenes.scene2d.Stage.draw(Stage.java:129)

I think that start and end are not aware that markup glyphs are not rendered, and so the range is higher then the size of glyphPositions array

int start = Math.max(linesBreak.get(i), minIndex);
int end = Math.min(linesBreak.get(i + 1), maxIndex);

Where could be the right place to fix this? Thanks

LibGDX and VisUI doesn't support color markup for any text field iirc, see #313.
Can you reproduce this with libgdx's TextArea?

fgnm commented

TextArea don't work at all, I've got an empty rendering, while VisTextArea works overall well, it's broken just the selection, this is a screen of a VisTextArea rendering color markup string
immagine

It's a pity that VisUI does not support color markup just for this selection issue 😃

VisTextArea is mostly a copy of TextArea so something must have changed. I remember it working in TextArea (or TextField?) with issues.
I'm guessing fixing this requires parsing the text to remove color markup before it's used for selection and others functions. I'd nice if this was working in libGDX, I never wanted to change VisTextArea too much.