Strange libgdx TextField ui render error (IndexOutOfBoundsException)

I only get this error once at a time when libgdx ui renders:

09-25 17:50:26.779  31171-32670/se.company.app.android E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 1126
Process: se.company.app.android, PID: 31171
java.lang.IndexOutOfBoundsException: index can't be >= size: 36 >= 36
        at com.badlogic.gdx.utils.FloatArray.get(FloatArray.java:104)
        at com.badlogic.gdx.scenes.scene2d.ui.TextField.calculateOffsets(TextField.java:214)
        at com.badlogic.gdx.scenes.scene2d.ui.TextArea.calculateOffsets(TextArea.java:266)
        at com.badlogic.gdx.scenes.scene2d.ui.TextField.draw(TextField.java:294)
        at com.badlogic.gdx.scenes.scene2d.Group.drawChildren(Group.java:123)
        at com.badlogic.gdx.scenes.scene2d.Group.draw(Group.java:57)
        at com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup.draw(WidgetGroup.java:154)
        at com.badlogic.gdx.scenes.scene2d.ui.Table.draw(Table.java:117)
        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 se.company.app.screens.AbstractScreen.render(AbstractScreen.java:36)
        at se.company.app.screens.InstructionsScreen.render(InstructionsScreen.java:80)
        at com.badlogic.gdx.Game.render(Game.java:46)
        at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:422)
        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1522)
        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
09-25 17:50:30.823  31171-31171/se.company.app.android E/AndroidGraphics﹕ waiting for pause synchronization took too long; assuming deadlock and killing
09-25 17:50:30.833  31171-31171/se.company.app.android I/Process﹕ Sending signal. PID: 31171 SIG: 9

      

I can't figure out what this is about. Question on the topic? But what? When I set the text, I do it with Gdx.app.postRunnable ().

I have classes:

public class InstructionsScreen extends AbstractScreen {

private InputProcessor inputProcessor = new InputAdapter() {
    @Override
    public boolean keyDown(int keycode) {
        if ((keycode == Input.Keys.ESCAPE) || (keycode == Input.Keys.BACK) ) {
            game.setScreen(new BeginGameOptionsScreen(game, resources));
        }
        return false;
    }
};

private Table table;
private ScrollPane resultsTextAreaScrollPane;
private TextArea resultsTextArea;

private TextArea textArea;
private float maxX,maxY,maxZ;
private Sound sound;
private long timer=0;

public InstructionsScreen(GameClass game, Resources resources) {
    super(game, resources);
}

@Override
public void resize(int width, int height) {

    addInputProcessor(inputProcessor);

    table = new Table();
    table.setFillParent(true);
    stage.addActor(table);

    TextArea resultsTextAreaBool;
    resultsTextAreaBool = new TextArea("", resources.getSkin());
    resultsTextAreaBool.setDisabled(true);
    resultsTextAreaBool.setText(String.valueOf(Gdx.input.isPeripheralAvailable(Input.Peripheral.Accelerometer)));
    table.add(resultsTextAreaBool).width(GraphicUtils.widthOfScreen(90)).height(GraphicUtils.heightOfScreen(20)).pad(GraphicUtils.onePercentHeight, GraphicUtils.onePercentWidth, GraphicUtils.onePercentHeight, GraphicUtils.onePercentWidth);
    table.row();

    resultsTextArea = new TextArea("", resources.getSkin());
    resultsTextArea.setDisabled(true);
    resultsTextArea.setText("");
    table.add(resultsTextArea).width(GraphicUtils.widthOfScreen(90)).height(GraphicUtils.heightOfScreen(40)).pad(GraphicUtils.onePercentHeight, GraphicUtils.onePercentWidth, GraphicUtils.onePercentHeight, GraphicUtils.onePercentWidth);
    table.row();

    sound=resources.getRobotBlip();
}

@Override
public void render(float delta) {
    super.render(delta);

    float accelX = Gdx.input.getAccelerometerX();
    float accelY = Gdx.input.getAccelerometerY();
    float accelZ = Gdx.input.getAccelerometerZ();

    if(accelX>maxX)
        maxX=accelX;
    if(accelY>maxY)
        maxY=accelY;
    if(accelZ>maxZ)
        maxZ=accelZ;

    if(Math.abs(maxX)>19f) {
        timer++;
    }

    if(timer==1) {
        sound.play();
    }

    if(timer>20) {
        timer=0;
        maxX=0;
    }

    Gdx.app.postRunnable(new Runnable() {
        @Override
        public void run() {
            resultsTextArea.setText("x=" + String.valueOf(maxX) + "\ny=" + String.valueOf(maxY) + "\nz=" + String.valueOf(maxZ));
        }
    });

}

      

}

The problem seems to be due to the newlines "\ n" in the String above. I am using FreeTypeFontGenerator to create fonts on the fly:

    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/anonymous-pro/Anonymous_Pro.ttf"));
    FreeTypeFontGenerator.FreeTypeFontParameter freeTypeFontParameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
    freeTypeFontParameter.borderColor = Color.BLACK;
    freeTypeFontParameter.borderWidth = 1;

    freeTypeFontParameter.size = (int)(Gdx.graphics.getWidth()/25.0f); 

    anonymous_pro = generator.generateFont(freeTypeFontParameter);
    generator.dispose();

      

What I am adding with:

    TextField.TextFieldStyle textFieldStyle=skin.get("default", TextField.TextFieldStyle.class);
    textFieldStyle.font=anonymous_pro;
    skin.add("default", textFieldStyle);

      

And get with:

resultsTextArea = new TextArea("", resources.getSkin()); //Resources is my own class

      

+1


source to share


1 answer


I hope you will excuse me for running into this old problem, especially when you already have an answer. This page is one of the few google links on the subject and I found another solution.

Long story short, I had to open the .fnt file I was using and remove glyph references 0 and 10. I know you are using FreeTypeFontGenerator, but I suspect it generates Glyph values ​​for character codes 0 and 10, too. For people using Hiero or another generator, you can edit the .fnt file and change the following lines:

chars count=98
char id=0       x=0    y=0    width=0    height=0    xoffset=-1   yoffset=0    xadvance=9    page=0    chnl=0 
char id=10      x=0    y=0    width=0    height=0    xoffset=-1   yoffset=0    xadvance=0    page=0    chnl=0 
char id=32      x=0    y=0    width=0    height=0    xoffset=-1   yoffset=0    xadvance=9    page=0    chnl=0 

      

For



chars count=96
char id=32      x=0    y=0    width=0    height=0    xoffset=-1   yoffset=0    xadvance=9    page=0    chnl=0 

      

Note that id = 0 and id = 10 are gone and the counter is updated.

This GitHub issue addresses the root of the issue: https://github.com/libgdx/libgdx/issues/4570

0


source







All Articles