OutOfMemory error from importer

When trying to import a fairly large object the importer will frequently crash with an OutOfMemory type error:

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.OutOfMemoryError: Direct buffer memory
at java.nio.Bits.reserveMemory(Bits.java:658)
at java.nio.DirectByteBuffer.(DirectByteBuffer.java:123)
at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:311)
at com.jme3.util.BufferUtils.createFloatBuffer(BufferUtils.java:831)
at com.jme3.scene.plugins.OBJLoader.constructMesh(OBJLoader.java:481)
at com.jme3.scene.plugins.OBJLoader.createGeometry(OBJLoader.java:414)
at com.jme3.scene.plugins.OBJLoader.load(OBJLoader.java:609)
at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:288)
at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:374)
at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:378)

Is there any thing that can be done about this? The model is large, but in terms of memory footprint should be similar to other models we have sucessfully imported in the past. Is there something specific to be aware of that will cause the OBJLoader class to cast an OutOfMemoryException?

Workaround : you can try to “temporary” increase the memory

-XX:MaxDirectMemorySize=512m

If you use SDK to do the conversion, add this arguments to “default_options” in jmonkeyplatform/etc/jmonkeyplatform.conf

1 Like

MaxDirectMemorySize is already set to 2048M here, so that’s probably not the problem.

As I said, in terms of the total size of the import file + textures, the model is on par with what we’ve imported in the past. I will try to revert back to the standard JMonkey OBJLoader as I have a couple local changes to that class, to see if that will help.

Note: when that value is too large for the JVM to handle then it simply ignores it and goes back to defaults. I ended up setting those values smaller so that they were actually larger for me… like I set them to 1024m. Because the defaults are way too small.

I am able to load it now through the jmonkey platform directly - however not in my Netbeans-based application. Netbeans is a memory management nightmare though so I can’t be surprised.

I didn’t know that the JVM silently switches back to the 2005 level defaults if it fails to acquire the requested amount of memory, that’s somewhat inconvenient …