Multiple ArrayIndexOutOfBoundsExceptions when loading a large j3o scene

When I loading a large scene (60 objects, 11k verts) at runtime, I get 25 ArrayIndexOutOfBoundsExceptions, all exactly the same:

May 10, 2023 7:30:22 AM class com.jme3.export.binary.BinaryImporter readObject(int id)
SEVERE: Exception
java.lang.ArrayIndexOutOfBoundsException: Index -97 out of bounds for length 4
	at com.jme3.export.binary.ByteUtils.rightAlignBytes(ByteUtils.java:483)
	at com.jme3.export.binary.BinaryInputCapsule.readInt(BinaryInputCapsule.java:834)
	at com.jme3.export.binary.BinaryInputCapsule.readString(BinaryInputCapsule.java:1017)
	at com.jme3.export.binary.BinaryInputCapsule.setContent(BinaryInputCapsule.java:234)
	at com.jme3.export.binary.BinaryImporter.readObject(BinaryImporter.java:340)
	at com.jme3.export.binary.BinaryInputCapsule.resolveIDs(BinaryInputCapsule.java:510)
	at com.jme3.export.binary.BinaryInputCapsule.readStringSavableMap(BinaryInputCapsule.java:700)
	at com.jme3.scene.Spatial.read(Spatial.java:1630)
	at com.jme3.scene.Geometry.read(Geometry.java:720)
	at com.jme3.export.binary.BinaryImporter.readObject(BinaryImporter.java:345)
	at com.jme3.export.binary.BinaryInputCapsule.resolveIDs(BinaryInputCapsule.java:510)
	at com.jme3.export.binary.BinaryInputCapsule.readSavableArray(BinaryInputCapsule.java:498)
	at com.jme3.export.binary.BinaryInputCapsule.readSavableArrayList(BinaryInputCapsule.java:616)
	at com.jme3.scene.Node.read(Node.java:768)
	at com.jme3.export.binary.BinaryImporter.readObject(BinaryImporter.java:345)
	at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:245)
	at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:128)
	at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:112)
	at com.jme3.export.binary.BinaryLoader.load(BinaryLoader.java:36)
	at com.jme3.asset.DesktopAssetManager.loadLocatedAsset(DesktopAssetManager.java:272)
	at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:388)
	at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:439)
	at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:444)
	at codex.dreamraid.Main.simpleInitApp(Main.java:65)
	at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:240)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:139)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:221)
	at java.base/java.lang.Thread.run(Thread.java:829)

The exceptions do not stop the program, and the scene seems to show up fine. The scene was exported from blender using gltf.

I don’t know if this has anything to do with issue, but when converting the scene from gltf to j3o, I got the following warnings:

Cannot create unique name for Spatial Cube.034 (Geometry): /Scene/Cube.034
Cannot create unique name for Spatial Cube.008 (Geometry): /Scene/Cube.008
Cannot create unique name for Spatial Cube.008 (Geometry): /Scene/Cube.008
Cannot create unique name for Spatial Cube.008 (Geometry): /Scene/Cube.008
Cannot create unique name for Spatial Cube.021 (Geometry): /Scene/Cube.021
Cannot create unique name for Spatial Cube.024 (Geometry): /Scene/Cube.024
Cannot create unique name for Spatial Cube.008 (Geometry): /Scene/Cube.008
Cannot create unique name for Spatial Cube.008 (Geometry): /Scene/Cube.008
Cannot create unique name for Spatial Cube.008 (Geometry): /Scene/Cube.008
Cannot create unique name for Spatial Cube.008 (Geometry): /Scene/Cube.008

It might be relevant so note that there are quite a few versions of JME and way more versions of Blender.

2 Likes

Oh yeah, didn’t think about that. :stuck_out_tongue_winking_eye:
I am using JME 3.5 and Blender 2.79 (later versions are slow on my computer).

1 Like

The scene can be found at this repository as castle_gates.blend and castle_gates.j3o

I think I went through a similar error like this before, maybe I don’t remember exactly, there might be problems with reading the spatial names, so they might be missed when rendering the scene, you may try to use better unique names for every object in the scene.

EDIT:
If you want to debug the problem, you need to read the j3o and the blend file into human-readable entries, and compare them.

You may also try updating to a more recent JME. Not sure if it will fix the issue but I do know that the gltf loader gets some love from time to time.