Bug when set text in a Text object

  ... in the unlikely case you discovered a bug, post it here.

Bug when set text in a Text object

Postby prchakal » Sun May 06, 2012 6:18 am

Hi,

I make a Text object to show the player score on window top.

When i create the text element and set text on constructor, it shows OK.
But when i use the "setText method" with value bigger than one character (number "10" for example) i got error:

05-06 23:54:22.629: E/AndroidRuntime(3769): FATAL EXCEPTION: UpdateThread
05-06 23:54:22.629: E/AndroidRuntime(3769): java.lang.ArrayIndexOutOfBoundsException: length=30; index=30
05-06 23:54:22.629: E/AndroidRuntime(3769): at org.andengine.entity.text.vbo.HighPerformanceTextVertexBufferObject.onUpdateVertices(HighPerformanceTextVertexBufferObject.java:121)
05-06 23:54:22.629: E/AndroidRuntime(3769): at org.andengine.entity.text.Text.onUpdateVertices(Text.java:335)
05-06 23:54:22.629: E/AndroidRuntime(3769): at org.andengine.entity.text.Text.setText(Text.java:223)
05-06 23:54:22.629: E/AndroidRuntime(3769): at com.prsolucoes.flyforcoins.entities.ScoreBox.setPoints(ScoreBox.java:69)
05-06 23:54:22.629: E/AndroidRuntime(3769): at com.prsolucoes.flyforcoins.entities.ScoreBox$1.onAreaTouched(ScoreBox.java:42)
05-06 23:54:22.629: E/AndroidRuntime(3769): at org.andengine.entity.scene.Scene.onAreaTouchEvent(Scene.java:409)
05-06 23:54:22.629: E/AndroidRuntime(3769): at org.andengine.entity.scene.Scene.onSceneTouchEvent(Scene.java:357)
05-06 23:54:22.629: E/AndroidRuntime(3769): at org.andengine.engine.Engine.onTouchScene(Engine.java:449)
05-06 23:54:22.629: E/AndroidRuntime(3769): at org.andengine.engine.Engine.onTouchEvent(Engine.java:435)
05-06 23:54:22.629: E/AndroidRuntime(3769): at org.andengine.input.touch.controller.BaseTouchController$TouchEventRunnablePoolItem.run(BaseTouchController.java:102)
05-06 23:54:22.629: E/AndroidRuntime(3769): at org.andengine.util.adt.pool.RunnablePoolUpdateHandler.onHandlePoolItem(RunnablePoolUpdateHandler.java:54)
05-06 23:54:22.629: E/AndroidRuntime(3769): at org.andengine.util.adt.pool.RunnablePoolUpdateHandler.onHandlePoolItem(RunnablePoolUpdateHandler.java:1)
05-06 23:54:22.629: E/AndroidRuntime(3769): at org.andengine.util.adt.pool.PoolUpdateHandler.onUpdate(PoolUpdateHandler.java:88)
05-06 23:54:22.629: E/AndroidRuntime(3769): at org.andengine.input.touch.controller.BaseTouchController.onUpdate(BaseTouchController.java:62)
05-06 23:54:22.629: E/AndroidRuntime(3769): at org.andengine.engine.Engine.onUpdate(Engine.java:581)
05-06 23:54:22.629: E/AndroidRuntime(3769): at org.andengine.engine.Engine.onTickUpdate(Engine.java:545)
05-06 23:54:22.629: E/AndroidRuntime(3769): at org.andengine.engine.Engine$UpdateThread.run(Engine.java:817)


The error is because one index of array is out of bounds and it is in the class "HighPerformanceTextV" on line number "121" and the code of this line is:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.         public void onUpdateVertices(final Text pText) {
  3.             ......
  4.             -->> bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x;
  5.             ......
  6.        }
  7.  
Parsed in 0.012 seconds, using GeSHi 1.0.8.4


The code that i use to create the Text object is:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private void createFont() {
  2.         this.mFontTexture = new BitmapTextureAtlas(GameObjects.GAME_ACTIVITY.getTextureManager(), 256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  3.         this.mFont = new Font(GameObjects.GAME_ACTIVITY.getFontManager(),this.mFontTexture, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 15, true, Color.BLACK);
  4.         GameObjects.GAME_ACTIVITY.getTextureManager().loadTexture(this.mFontTexture);
  5.         GameObjects.GAME_ACTIVITY.getFontManager().loadFont(this.mFont);
  6.        
  7.         textPoints = new Text(0, 0, this.mFont, Integer.toString(GameObjects.PLAYER_SCORE), new TextOptions(HorizontalAlign.CENTER), GameObjects.GAME_ACTIVITY.getVertexBufferObjectManager());
  8.                
  9.         final float posX = (sprite.getWidth() / 2) - (textPoints.getWidth() / 2);
  10.         final float posY = sprite.getY() + 16;
  11.  
  12.         textPoints.setPosition(posX, posY);
  13.                
  14.         sprite.attachChild(textPoints);
  15. }
  16.  
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


And the code that i use to change the text is:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void setPoints() {
  2.         textPoints.setText(Integer.toString(10));
  3. }
  4.  
Parsed in 0.010 seconds, using GeSHi 1.0.8.4


It i call "textPoints.setText(Integer.toString(9));" it works, but with "textPoints.setText(Integer.toString(10));" i got that error. :(
prchakal
 
Posts: 42
Joined: Tue May 01, 2012 3:56 pm

Re: Bug when set text in a Text object

Postby xiaobo68688 » Mon May 07, 2012 12:16 pm

:D
You can create your text like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. textPoints = new Text(0, 0, this.mFont, Integer.toString(GameObjects.PLAYER_SCORE) + "           ", new TextOptions(HorizontalAlign.CENTER), GameObjects.GAME_ACTIVITY.getVertexBufferObjectManager());
Parsed in 0.010 seconds, using GeSHi 1.0.8.4


It is worked for me! :D
xiaobo68688
 
Posts: 5
Joined: Thu Oct 27, 2011 8:11 am

Re: Bug when set text in a Text object

Postby prchakal » Mon May 07, 2012 2:08 pm

if you read, the problem is not to create, but after created, set a new text.
prchakal
 
Posts: 42
Joined: Tue May 01, 2012 3:56 pm

Re: Bug when set text in a Text object

Postby nxnwsoftware » Mon May 07, 2012 2:32 pm

the problem is in your create statement - you are using the wrong constructor for your Text object. use one like this one
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public Text(final float pX, final float pY, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final VertexBufferObjectManager pVertexBufferObjectManager) {
Parsed in 0.010 seconds, using GeSHi 1.0.8.4


the pCharacterMaximum value needs to be large enough to contain all your text. If you don't use this constructor, then AndEngine sets the maximum length to the length of the CharSequence used when you created the Text object.

Once you surpass that length, you get the error - i.e. "9" works, "10" doesn't
nxnwsoftware
 
Posts: 96
Joined: Wed Jan 11, 2012 1:01 am
Location: DFW Area, Texas, USA

Re: Bug when set text in a Text object

Postby siddharth3322 » Sat Jun 08, 2013 8:23 am

I have similar problem in setText but using last post suggestion I got my thing working.
siddharth3322
 
Posts: 243
Joined: Thu Jan 03, 2013 10:10 am

Re: Bug when set text in a Text object

Postby Sprk » Sun Mar 30, 2014 7:35 pm

Indeed. I had the same learning experience.

It's the max length you need to reserve, see the underlined text.

text = new Text(10, 10, this.mFont, "Some Text", "Some Text : XXXX".length(), this.getVertexBufferObjectManager());
Sprk
 
Posts: 1
Joined: Sun Mar 30, 2014 11:49 am


Return to Bugs

Who is online

Users browsing this forum: No registered users and 1 guest