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

TextField crash when writing brackets if color markup is enabled #4576

Closed
7 tasks done
MrPlow442 opened this issue Jan 28, 2017 · 3 comments · Fixed by #7383
Closed
7 tasks done

TextField crash when writing brackets if color markup is enabled #4576

MrPlow442 opened this issue Jan 28, 2017 · 3 comments · Fixed by #7383

Comments

@MrPlow442
Copy link

MrPlow442 commented Jan 28, 2017

Issue details

Opening and closing brackets [] when color markup is enabled causes an IndexOutOfBoundsException regardless of how many characters are between the brackets

Reproduction steps/code

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.utils.viewport.FitViewport;

/** {@link com.badlogic.gdx.ApplicationListener} implementation shared by all platforms. */
public class Test extends ApplicationAdapter {
    private Stage stage;
    private Skin skin;

    @Override
    public void create() {
        stage = new Stage(new FitViewport(640, 480));
        skin = new Skin(Gdx.files.internal("skin.json"));

        BitmapFont font = skin.getFont("default-font");

        font.getData().markupEnabled = true;

        stage.addActor(new TextField("", skin));

        Gdx.input.setInputProcessor(stage);
    }

    @Override
    public void render() {
        Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        stage.act(Gdx.graphics.getDeltaTime());
        stage.draw();
    }

    @Override
    public void resize(int width, int height) {
        stage.getViewport().update(width, height);
    }

    @Override
    public void dispose() {
        stage.dispose();
        skin.dispose();
    }
}

Version of LibGDX and/or relevant dependencies

Attempted on LibGDX versions 1.9.5 and 1.9.6-SNAPSHOT

Stacktrace

Exception in thread "LWJGL Application" java.lang.IndexOutOfBoundsException: index can't be >= size: 2 >= 1
	at com.badlogic.gdx.utils.FloatArray.get(FloatArray.java:104)
	at com.badlogic.gdx.scenes.scene2d.ui.TextField.drawCursor(TextField.java:373)
	at com.badlogic.gdx.scenes.scene2d.ui.TextField.draw(TextField.java:343)
	at com.badlogic.gdx.scenes.scene2d.Group.drawChildren(Group.java:110)
	at com.badlogic.gdx.scenes.scene2d.Group.draw(Group.java:57)
	at com.badlogic.gdx.scenes.scene2d.Stage.draw(Stage.java:128)
	at test.Test.render(Test.java:82)
	at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:225)
	at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)

Please select the affected platforms

  • Android
  • iOS (robovm)
  • iOS (MOE)
  • HTML/GWT
  • Windows
  • Linux
  • MacOS
@metaphore
Copy link
Contributor

metaphore commented Jan 22, 2018

I've recently come across this problem and found a lot of GitHub issues about it. It's an old case and seems like @badlogic's comment is still reflects reality:

... markup on textfields/areas is not supported. Happy to merge PRs ...

But I'm curious why not just disable color markup completely for input widgets? I'm pretty sure noone really uses it for TextField/TextArea because it leads to crash, so the change shouldn't break anything. I see easiest solution is to add ignoreColorMarkup flag to GlyphLayout and switch it for instances that are used by text edit widgets. I've tryed it on my side, and seems everything is ok.

@NathanSweet I can make a PR if the approach is fine.

@NathanSweet
Copy link
Member

@metaphore Disabling color markup for text field/areas sounds OK.

@mcol
Copy link

mcol commented Apr 1, 2024

I've encountered this crash too, as it's not documented (outside of github issues) that markup should not be used in TextAreas.

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

Successfully merging a pull request may close this issue.

4 participants