Monday 29 November 2010

Getting FloatBuffer data: BufferUnderFlowException

When getting FloatBuffer data from a mesh, you must be sure to rewind your buffer before copying it if you already have before. I was iterating subsets of vertex data for the same mesh (I have "submeshes", which are equivalent to Wavefront .obj groups or objects) and trying to get the vertex data for each submesh for some processing, but the second iteration I was getting a BufferUnderFlowException.

It took me longer than it probably should have to realise I needed to "rewind" the buffer so I could copy the data again. To do this simply call FloatBuffer.position() with zero to set its internal position back to the start.

Of course if you need to be performant, you probably shouldn't be copying it twice anyway... :)

No comments:

Post a Comment