Out of Memory Error

I’ve recently been trying out jMonkey within the jMonkey SDK 3.0 beta and in my latest project i’ve encounted an error that i’m not that familar with from previous work with Java.



I’m basically running an extended version of the hello terrain tutorial with some larger heightmaps currently but i’m now hitting this Out of Memory Error:



Nov 24, 2011 10:34:44 AM com.jme3.app.Application handleError

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:122)

at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:306)

at com.jme3.util.BufferUtils.createFloatBuffer(BufferUtils.java:785)

at com.jme3.terrain.geomipmap.LODGeomap.createMesh(LODGeomap.java:85)

at com.jme3.terrain.geomipmap.LODGeomap.createMesh(LODGeomap.java:77)

at com.jme3.terrain.geomipmap.TerrainPatch.(TerrainPatch.java:193)

at com.jme3.terrain.geomipmap.TerrainQuad.createQuadPatch(TerrainQuad.java:762)

at com.jme3.terrain.geomipmap.TerrainQuad.split(TerrainQuad.java:608)

at com.jme3.terrain.geomipmap.TerrainQuad.(TerrainQuad.java:190)

at com.jme3.terrain.geomipmap.TerrainQuad.createQuad(TerrainQuad.java:691)

at com.jme3.terrain.geomipmap.TerrainQuad.split(TerrainQuad.java:610)

at com.jme3.terrain.geomipmap.TerrainQuad.(TerrainQuad.java:190)

at com.jme3.terrain.geomipmap.TerrainQuad.createQuad(TerrainQuad.java:651)

at com.jme3.terrain.geomipmap.TerrainQuad.split(TerrainQuad.java:610)

at com.jme3.terrain.geomipmap.TerrainQuad.(TerrainQuad.java:190)

at com.jme3.terrain.geomipmap.TerrainQuad.createQuad(TerrainQuad.java:651)

at com.jme3.terrain.geomipmap.TerrainQuad.split(TerrainQuad.java:610)

at com.jme3.terrain.geomipmap.TerrainQuad.(TerrainQuad.java:190)

at com.jme3.terrain.geomipmap.TerrainQuad.createQuad(TerrainQuad.java:651)

at com.jme3.terrain.geomipmap.TerrainQuad.split(TerrainQuad.java:610)

at com.jme3.terrain.geomipmap.TerrainQuad.(TerrainQuad.java:190)

at com.jme3.terrain.geomipmap.TerrainQuad.createQuad(TerrainQuad.java:711)

at com.jme3.terrain.geomipmap.TerrainQuad.split(TerrainQuad.java:610)

at com.jme3.terrain.geomipmap.TerrainQuad.(TerrainQuad.java:190)

at com.jme3.terrain.geomipmap.TerrainQuad.createQuad(TerrainQuad.java:651)

at com.jme3.terrain.geomipmap.TerrainQuad.split(TerrainQuad.java:610)

at com.jme3.terrain.geomipmap.TerrainQuad.(TerrainQuad.java:190)

at com.jme3.terrain.geomipmap.TerrainQuad.(TerrainQuad.java:153)

at com.jme3.terrain.geomipmap.TerrainQuad.(TerrainQuad.java:145)

at mygame.Terrain.CreateTerrain(Terrain.java:84)

at mygame.Terrain.(Terrain.java:31)

at mygame.Main.simpleInitApp(Main.java:21)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:230)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)

at java.lang.Thread.run(Thread.java:722)



Anyone have any ideas how i would go around stopping this error?

Well assuming that you use only standart jme classes, and do not create meshes or textures manually without the loader.



Try to increase the directMemorySize the jvm has

use XX:MaxDirectMemorySize=1024m as jvm argument to increase it.

(Direct memory is needed to store the actual mesh as well as the texture data)

1 Like

had to go for a 2056m settingin the end but it solved the error. Thanks for the help.

@fatekeeper said:
had to go for a 2056m settingin the end but it solved the error. Thanks for the help.


Whoah... that's a lot of memory. You might consider strategies for reducing your mem requirements as you are severely limiting the types of hardware your game will run on decently, I think.

Probably you’re loading a huge heightmap. If you’re loading heightmaps larger than 1024x1024, you should really consider using the terrain grid system which streams it from disk rather than loading the whole thing entirely