Direct buffer memory

Is there a hard limit on a direct buffer?

I got a



java.lang.OutOfMemoryError: Direct buffer memory

        at java.nio.Bits.reserveMemory(Unknown Source)

        at java.nio.DirectByteBuffer.<init>(Unknown Source)

        at java.nio.ByteBuffer.allocateDirect(Unknown Source)

        at com.jme.util.geom.BufferUtils.createFloatBuffer(Unknown Source)

        at com.jme.util.geom.BufferUtils.createVector3Buffer(Unknown Source)

        at com.jmex.terrain.TerrainBlock.buildNormals(Unknown Source)

        at com.jmex.terrain.TerrainBlock.<init>(Unknown Source)

        at com.jmex.terrain.TerrainPage.createQuadBlock(Unknown Source)

        at com.jmex.terrain.TerrainPage.split(Unknown Source)

        at com.jmex.terrain.TerrainPage.<init>(Unknown Source)

        at com.jmex.terrain.TerrainPage.createQuadPage(Unknown Source)

        at com.jmex.terrain.TerrainPage.split(Unknown Source)

        at com.jmex.terrain.TerrainPage.<init>(Unknown Source)





while loading a TerrainPage.

You're likely using more memory than the default VM heapsize. This can be changed with VM parameters -Xms -Xmx and -Xmn. I'm Sun has some official page explaining them but a quick Google comes up with, for example, http://www.caucho.com/resin-3.0/performance/jvm-tuning.xtp

I already set -Xmx1024m. The problem is that the map is just too big to be loaded in one chunk. Dynamic loading and unloading of tiles is the only way around.

The map is 4096x4096 height points.

Still, the only reason you should get this Exception other than that you're simply out of memory.



(very) roughly:



4096 x 4096 x 4 bytes (a float or an int) x 15 (~ at least 2 heightmap int, 3 vertexpoints, 3 normals, 3 indices, 2 texturepoints… and I don't think terrain uses color anymore)



then you're over 900MB already, so eg. if you're using clod then you're probably hitting the 1024 you specified. Try specifying something higher, or turning of clod if you're using that.



I restored the backup of my streaming terrain project and I'm gonna work some more on that project tonight, however if you're using many of the existing terrainpage/block functions (like getting the height at a certain point) that won't help you much any time soon (though if it's only a few it should be easy to readd them).

I started to work on a SlidingTerrainPage which will keep track of single TerrainBlocks and loads/unloads these dynamically.



It's only half-way done and not yet tested: http://cvs.world-of-mystery.de/cgi-bin/cvsweb.cgi/wom/src/de/worldofmystery/client/SlidingTerrainPage.java

Nevertheless feedback is appreciated.