java.nio.BufferUnderflowException with JmeBinaryWriter

Hi,



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,
cj

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")) ;
      
   try
   {
      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)
   {
      ...
      e.printStackTrace();
   }
}




Here is the output:

java.lang.reflect.InvocationTargetException
   at java.awt.EventQueue.invokeAndWait(EventQueue.java:851)
   at javax.swing.SwingUtilities.invokeAndWait(SwingUtilities.java:1257)
   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(Buffer.java:398)
   at java.nio.DirectFloatBufferU.get(DirectFloatBufferU.java:205)
   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.

Hi,



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




    public static ColorRGBA[] getColorArray(FloatBuffer buff) {
        buff.rewind();
        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(),
                    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.



cj

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