Weird BitmapText update error

So, quick background, I display the user’s location x,y,z as a “%.2f, %2f, %2f” formatted string. For some reason, as soon as the user crossed from 999.99 to 1000.00 the BitmapText just stops updating. I’ve looked into it a bit and it’s kind of bizarre. If I initialize the BitmapText’s starting text bigger than I initially need then it works fine.



Creating a test case, I discovered the crucial step to getting it to fail. Simply calling BitmapText.getLineWidth() causes the update issue.



Here is the test case with comments:

[java]

package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.font.BitmapText;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;



/**

  • test
  • @author normenhansen

    */

    public class Main extends SimpleApplication {



    private BitmapText label;

    private float counter = 900;



    public static void main(String[] args) {

    Main app = new Main();

    app.start();

    }



    @Override

    public void simpleInitApp() {

    Box b = new Box(Vector3f.ZERO, 1, 1, 1);

    Geometry geom = new Geometry("Box", b);

    geom.updateModelBound();



    Material mat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");

    mat.setColor("m_Color", ColorRGBA.Blue);

    geom.setMaterial(mat);

    rootNode.attachChild(geom);



    label = new BitmapText(guiFont, false);

    label.setSize(17);

    label.setText("100.00, 100.00, 100.00");

    label.setLocalTranslation( cam.getWidth()/2, cam.getHeight()/2, 0 );



    // This call is here to make the label fail to update

    // once the counter grows beyond 999.99.

    // The following commented out line is why one might want

    // to do such a thing normally… but just the getLineWidth()

    // is enough to cause it to fail.

    label.getLineWidth();

    //label.setLocalTranslation( cam.getWidth() - label.getLineWidth() - 20,

    // label.getLineHeight() * 2, 0 );

    guiNode.attachChild(label);

    }



    @Override

    public void simpleUpdate(float tpf) {

    counter += 0.01;

    String text = String.format( "%.2f, 100.00, 10.00", counter );

    label.setText(text);

    //label.setLocalTranslation( cam.getWidth() - label.getLineWidth() - 20,

    // label.getLineHeight() * 2, 0 );

    }



    @Override

    public void simpleRender(RenderManager rm) {

    //TODO: add render code

    }

    }

    [/java]



    If you run that, the label should count up to 999.99 or so and then stop updating. The number still updates, the text value of BitmapText still updates… just no more geometry updates.

Simple yet so deadly

@Yonghoon or @moluva might want to take a look at this …

I should probably note that if the counter were to go back down below 1000 that it would start rendering again… in case that wasn’t obvious.

This bug has been fixed right? Running the test case now I see that the text can properly go beyond 1000 with or without getLineWidth

Cool… I will have to undo my work-around some time and see.