Zaylyaev / jmonkeyengine

Automatically exported from code.google.com/p/jmonkeyengine
0 stars 0 forks source link

Increasing text length in BitmapText causes IndexOutOfBoundsException to be thrown on Android #486

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The problem occurs on Android when increasing the size of a piece of text for a 
BitmapText object so that it triggers a call to 
BufferUtils.ensureLargeEnough(), this then triggers an allocation of a new 
larger Float buffer. The code then tries to copy the contents of the original 
buffer over which then causes a IndexOutOfBoundsException to be thrown. The 
problem is a general problem in the BufferUtils.ensureLargeEnough() code where 
buffer.rewind() is being called when buffer.flip() should be used. Calling 
flip() updates the Buffer objects “limit” field to match the current data 
size. The exception was being thrown because the limit field had an incorrect 
value.

After the fix flip() fix was applied there was no problem growing the text 
length and the full string was displayed.

public static FloatBuffer ensureLargeEnough(FloatBuffer buffer, int required) {
if (buffer == null || (buffer.remaining() < required)) {
int position = (buffer != null ? buffer.position() : 0);
FloatBuffer newVerts = createFloatBuffer(position + required);
if (buffer != null) {
/*********************************************************
Fix the original code called: buffer.rewind(), it should call flip makes a 
buffer ready for a new sequence of channel-write or relative get operations 
see: http://docs.oracle.com/javase/1.4.2/docs/api/java/nio/Buffer.html
Clearing, flipping and rewinding
*************************************************/
buffer.flip();
newVerts.put(buffer);
newVerts.position(position);
}
buffer = newVerts;
}
return buffer;
}

Original issue reported on code.google.com by danielbr...@gmail.com on 29 Mar 2012 at 3:23

Attachments:

GoogleCodeExporter commented 8 years ago
Dup entry of issue 485, sorry about that.

Original comment by danielbr...@gmail.com on 29 Mar 2012 at 3:26

GoogleCodeExporter commented 8 years ago
Thanks i'm gonna look into it

Original comment by remy.bou...@gmail.com on 7 Apr 2012 at 8:05

GoogleCodeExporter commented 8 years ago
fixed in revision http://code.google.com/p/jmonkeyengine/source/detail?r=9278
thanks

Original comment by remy.bou...@gmail.com on 7 Apr 2012 at 8:34