Strange buffer overflow exception

hi all

when i use my app jme3 on my phone with intensive touch screen movements i got this exception:





[java]

07-24 16:55:19.656: ERROR/Application(8017): java.lang.IndexOutOfBoundsException

07-24 16:55:19.656: ERROR/Application(8017): at java.nio.DirectByteBuffer.getShort(DirectByteBuffer.java:214)

07-24 16:55:19.656: ERROR/Application(8017): at java.nio.ShortToByteBufferAdapter.get(ShortToByteBufferAdapter.java:141)

07-24 16:55:19.656: ERROR/Application(8017): at java.nio.ShortBuffer.get(ShortBuffer.java:320)

07-24 16:55:19.656: ERROR/Application(8017): at java.nio.ShortBuffer.get(ShortBuffer.java:289)

07-24 16:55:19.656: ERROR/Application(8017): at java.nio.ShortBuffer.put(ShortBuffer.java:501)

07-24 16:55:19.656: ERROR/Application(8017): at com.jme3.util.BufferUtils.ensureLargeEnough(BufferUtils.java:1062)

07-24 16:55:19.656: ERROR/Application(8017): at com.jme3.font.BitmapTextPage.assemble(BitmapTextPage.java:165)

07-24 16:55:19.656: ERROR/Application(8017): at com.jme3.font.BitmapText.assemble(BitmapText.java:351)

07-24 16:55:19.656: ERROR/Application(8017): at com.jme3.font.BitmapText.updateLogicalState(BitmapText.java:342)

07-24 16:55:19.656: ERROR/Application(8017): at com.jme3.scene.Node.updateLogicalState(Node.java:153)

07-24 16:55:19.656: ERROR/Application(8017): at com.jme3.app.SimpleApplication.update(SimpleApplication.java:250)

07-24 16:55:19.656: ERROR/Application(8017): at com.jme3.system.android.OGLESContext.onDrawFrame(OGLESContext.java:386)

07-24 16:55:19.656: ERROR/Application(8017): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1332)

07-24 16:55:19.656: ERROR/Application(8017): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)



[/java]

anyone knows how to avoid it?

looks like a “text too big” in the fps / statistics bitmap text.



How can i reproduce that error?

my app transmit to another phone a string containing coords movements of a geometry.

Actually if i reduce fps this exception does not appear.But i d like to avoid it

With how many fps does it occur? Could it be that 4 digits fps is too large, because 3 digits works for me :slight_smile:

I would like to reproduce that bug.



This is for sure again a problem with nio, which is different on android in some areas.

i reduce io action and problem dissappear ; maybe i ask to much to my phone :slight_smile:

Hi,

I ran into the same problem and traced it to a problem in the BufferUtils.ensureLargeEnough() code. I’ve fixed the problem and submitted a patch:

Issue 485:Fix for BufferUtils.ensureLargeEnough(Buffer.java:1062) throws IndexOutOfBoundsException on Android



Here is copy of the issue report:

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;

}

2 Likes

noooooo, u brought dilembo back from the grave, @normen is gonna have nightmares again now :frowning:

@dbrunton thanks for the patch!

I can’t see any issue 485 in the tracker though.

I added it then went back to find it and didn’t see it either, so added another:

http://code.google.com/p/jmonkeyengine/issues/detail?id=486

But now unfortunately will see both: 486, a dup, and 485 the original if you set your search filter to ‘All issues’ and select sort down on the ID field.

lol strange…

anyway thanks :wink: