java.nio.BufferUnderflowException with JmeBinaryWriter


When i try to export my scene with JmeBinaryWriter and jbw.writeScene(), the software catches a BufferUnderflowException (see code and Excepion output):

  • The scene uses some jpg files for the textures (Mesh).

  • i am working with the last cvs version of jme.

  • When i simplify the scene, it creates both files (binary and xml).


I would like to know if it exists a description of the binary format and as well a description of the xml format (with DTD)?
I did not see it but is it possible to export a scene node in a xml file directly without using "JmeBinaryWriter" and "BinaryToXml"?

Many thanks,

Here is my code:

private void saveScene(File file , Node scenenode)

   // Send a jME SceneGraph to jME Binary
   JmeBinaryWriter jbw = new JmeBinaryWriter();

   File fbin = new File(file.getParent(), new String(file.getName() + ".jme"));
   File fxml = new File(file.getParent(), new String(file.getName() + ".xml")) ;
      FileOutputStream fos = new FileOutputStream(fbin);
      jbw.writeScene(scenenode, fos);
      ByteArrayOutputStream BO2 = new ByteArrayOutputStream();
      jbw.writeScene(scenenode, BO2);
      BinaryToXML btx = new BinaryToXML();
      btx.sendBinarytoXML(new ByteArrayInputStream(BO2.toByteArray()), new FileWriter(fxml));
   } catch (IOException e)

Here is the output:

   at java.awt.EventQueue.invokeAndWait(
   at javax.swing.SwingUtilities.invokeAndWait(
   at com.jmex.awt.swingui.JMEDesktop.onButton(Unknown Source)
   at com.jmex.awt.swingui.JMEDesktop$ButtonAction.performAction(Unknown Source)
   at com.jme.input.ActionTrigger.performAction(Unknown Source)
   at com.jme.input.InputHandler.update(Unknown Source)
   at com.jme.input.InputHandler.update(Unknown Source)
Caused by: java.nio.BufferUnderflowException
   at java.nio.Buffer.nextGetIndex(
   at java.nio.DirectFloatBufferU.get(
   at com.jme.util.geom.BufferUtils.getColorArray(Unknown Source)
   at com.jmex.model.XMLparser.JmeBinaryWriter.writeTriMeshTags(Unknown Source)
   at com.jmex.model.XMLparser.JmeBinaryWriter.writeMesh(Unknown Source)
   at com.jmex.model.XMLparser.JmeBinaryWriter.writeSpatial(Unknown Source)
   at com.jmex.model.XMLparser.JmeBinaryWriter.writeChildren(Unknown Source)
   at com.jmex.model.XMLparser.JmeBinaryWriter.writeNode(Unknown Source)
   at com.jmex.model.XMLparser.JmeBinaryWriter.writeSpatial(Unknown Source)
   at com.jmex.model.XMLparser.JmeBinaryWriter.writeScene(Unknown Source)

Yes, a description of the .jme formats would be quite helpful.

I'm somewhat stuck on the <jointindex> tag in jointmesh by now.


I think i found the problem : the method BufferUtils.getColorArray() has a bug.

    public static ColorRGBA[] getColorArray(FloatBuffer buff) {
        ColorRGBA[] colors = new ColorRGBA[buff.capacity() << 2];
        for (int x = 0; x < colors.length; x++) {
            ColorRGBA c = new ColorRGBA(buff.get(), buff.get(), buff.get(),
            colors[x] = c;
        return colors;

The allocation of the array should not be done with buff.capacity() << 2] but with buff.capacity() >> 2]

For example , for a capacity of 96 for "buff", it creates an array of colors with a size of 384. Then it throws an exception because there are only 24 colors.


confirmed, and fix is in CVS. Thanks for finding that.