Text setText isn working

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

Text setText isn working

Postby Nortsx » Fri Mar 30, 2012 2:17 pm

When i call the method setText of the Text class it crashes the application. Tested on Desire.
Nortsx
 
Posts: 67
Joined: Tue Dec 06, 2011 6:49 pm

Re: Text setText isn working

Postby OzLark » Fri Mar 30, 2012 3:18 pm

This is very unlikely to be a bug, a lot of people use setText with GLES2 on desires without issue - it is almost certainly something to do with the manner you're calling setText.
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: Text setText isn working

Postby Nortsx » Fri Mar 30, 2012 3:52 pm

OzLark wrote:This is very unlikely to be a bug, a lot of people use setText with GLES2 on desires without issue - it is almost certainly something to do with the manner you're calling setText.

Hmmm...ok let s try to understand my fault. Now i ll show the code.
I have a class which realises scrolling, and i want to watch debug information without touching the debugger.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. /*Initializing my texts, all texts have the Text type,and they re all public*/
  3.         public Text headerText;
  4.         public Text capitalText;
  5.         public Text turnText;
  6.  
  7.         public void setFonts(){
  8.                 capitalText = new Text(100,100,this.mMainFont,"Capital:",this.getVertexBufferObjectManager());
  9.                 headerText = new Text(100,200,this.mMainFont,"Header:",this.getVertexBufferObjectManager());
  10.                 turnText = new Text(100,300,this.mMainFont,"Turn:",this.getVertexBufferObjectManager());
  11.                 mScene.getChild(LAYER_GUI).attachChild(capitalText);
  12.                 mScene.getChild(LAYER_GUI).attachChild(headerText);
  13.                 mScene.getChild(LAYER_GUI).attachChild(turnText);
  14.         }
  15.        
  16.  
  17. /*wanna set text when finishing the scrolling and my camera position is over the width*/
  18.         public void onScrollFinished(ScrollDetector pScollDetector, int pPointerID,
  19.                         float pDistanceX, float pDistanceY) {
  20.                 final float zoomFactor = this.mCamera.getZoomFactor();
  21.                 float cX = this.mCamera.getCenterX() -pDistanceX / zoomFactor;
  22.                 float cY = this.mCamera.getCenterY() -pDistanceY / zoomFactor;
  23.                 if(cX>=CAMERA_WIDTH){
  24.                         capitalText.setText("cross over");/*it crashes in here*/
  25.                 }
  26.                 else{
  27.                         this.mCamera.offsetCenter(-pDistanceX / zoomFactor, -pDistanceY / zoomFactor);
  28.                 }
  29.                
  30.         }
  31.  
  32.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


what s wrong with it? Maybe this method called in separate thread which doesn t have any access to public fields of my main activity class, but it looks like kinda delirium=))
Nortsx
 
Posts: 67
Joined: Tue Dec 06, 2011 6:49 pm

Re: Text setText isn working

Postby OzLark » Fri Mar 30, 2012 3:57 pm

I'm pretty sure you need to use the:

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.031 seconds, using GeSHi 1.0.8.4


constructor variant. Note the pCharactersMaximum - this is the maximum chars the text can grow to.
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: Text setText isn working

Postby Nortsx » Fri Mar 30, 2012 4:22 pm

Huh it solved the half of a problem. Now it works but only for the first time. When i scroll it the second time instead of placing some figures into a text it crashes. Looks like stack overflowed somwhere?
Nortsx
 
Posts: 67
Joined: Tue Dec 06, 2011 6:49 pm

Re: Text setText isn working

Postby OzLark » Sat Mar 31, 2012 1:38 am

The rest of that code looks fine, the stack trace is your friend.
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: Text setText isn working

Postby Nortsx » Sat Mar 31, 2012 2:06 pm

Can you show the example of text changing in your code? I tried the Nicolas`s example with textchanging but it also crashed. I guess it s a bug anyway)
Nortsx
 
Posts: 67
Joined: Tue Dec 06, 2011 6:49 pm

Re: Text setText isn working

Postby Nortsx » Sat Mar 31, 2012 2:56 pm

That s an issue.
Two examples
WORKS FINE.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void startTurn(){
  2.         String s ="MONEY";
  3.         capitalText.setText(s);
  4. }
  5.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

DOESN T WORK (black screen and nothing more)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void startTurn(){
  2.         String s ="MONEY 500";
  3.         parent.capitalText.setText(s);
  4. }
  5.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

If i put the figures in constructor it works OK. What s the problem with that?
Nortsx
 
Posts: 67
Joined: Tue Dec 06, 2011 6:49 pm

Re: Text setText isn working

Postby OzLark » Sun Apr 01, 2012 1:06 am

If i put the figures in constructor it works OK. What s the problem with that?


The only thing that stands out to me is that "MONEY" is 5 chars long and "MONEY 500" is 9, does the constructor call specify at least 9 characters for pCharactersMaximum?
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: Text setText isn working

Postby Nortsx » Sun Apr 01, 2012 10:12 am

OzLark wrote:
If i put the figures in constructor it works OK. What s the problem with that?


The only thing that stands out to me is that "MONEY" is 5 chars long and "MONEY 500" is 9, does the constructor call specify at least 9 characters for pCharactersMaximum?

There is my constructor.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. capitalText = new Text(100,100,this.mMainFont,"Capital:",500,this.getVertexBufferObjectManager(),DrawType.DYNAMIC);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


It looks like anything that is longer than start string`s length doesn t go into the buffer and crashes somehow(with max length and DrawType.DYNAMIC applicatoion doesnt crash but i have the black screen).
Nortsx
 
Posts: 67
Joined: Tue Dec 06, 2011 6:49 pm

Next

Return to Bugs

Who is online

Users browsing this forum: No registered users and 1 guest