BinaryExporter/Importer issues

Hi,

Today I came across a problem with a Binary Exporter/Importer. I have constructed a simple test case. Could you verify if you also get the following problem? I am using jME3.1-stable

private static void testsave() {
		//no error at loop 1-15 i think
		//ClassCastException at loop = 50
		//ArrayIndexOutOfBoundsException at loop = 40
			
		
//		final int LOOPS = 1;
		final int LOOPS = 40;
//		final int LOOPS = 50;

					
		try {
			Geometry geom = new Geometry("test");
			
			ArrayList<Vector3f[]> faces = new ArrayList<>();
			
			for(int k = 0; k < LOOPS; k++) {
				Vector3f[] face = new Vector3f[]{Vector3f.UNIT_X,Vector3f.UNIT_XYZ, Vector3f.UNIT_Y,Vector3f.UNIT_Z};
				faces.add(face);
				faces.add(new Vector3f[]{});
				faces.add(null);
				faces.add(new Vector3f[]{Vector3f.UNIT_X});
			}
			
			
			geom.setUserData("keepquads", faces);
			
			BinaryExporter exp = BinaryExporter.getInstance();
			exp.save(geom, new File("test.j3o"));
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	private static void testload() {
		try {
			BinaryImporter im = BinaryImporter.getInstance();
			Geometry g = (Geometry)im.load( new File("test.j3o"));
			ArrayList<Vector3f[]> faces = g.getUserData("keepquads");
			System.out.println("Load Succeeded Yay");
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}	
	public static void main(String[] args) {
		//feel free to comment one line, to save first then load
		testsave();
		
		testload();
	}

The exceptions that I get are these:

java.lang.ArrayIndexOutOfBoundsException: -2
	at com.jme3.export.binary.ByteUtils.rightAlignBytes(ByteUtils.java:477)
	at com.jme3.export.binary.BinaryInputCapsule.readInt(BinaryInputCapsule.java:793)
	at com.jme3.export.binary.BinaryInputCapsule.setContent(BinaryInputCapsule.java:154)
	at com.jme3.export.binary.BinaryImporter.readObject(BinaryImporter.java:337)
	at com.jme3.export.binary.BinaryInputCapsule.resolveIDs(BinaryInputCapsule.java:483)
	at com.jme3.export.binary.BinaryInputCapsule.readStringSavableMap(BinaryInputCapsule.java:667)
	at com.jme3.scene.Spatial.read(Spatial.java:1651)
	at com.jme3.scene.Geometry.read(Geometry.java:612)
	at com.jme3.export.binary.BinaryImporter.readObject(BinaryImporter.java:342)
	at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:242)
	at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:129)
	at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:271)
	at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:265)
	at tests.TestWindow.testload(TestWindow.java:112)
	at tests.TestWindow.main(TestWindow.java:123)
java.lang.ClassCastException: java.lang.Float cannot be cast to java.util.ArrayList
	at tests.TestWindow.testload(TestWindow.java:113)
	at tests.TestWindow.main(TestWindow.java:123)

I get it with your test case.
You should mention that it works up to a certain number of items in the list too. (I see it now in your comment)

1 Like