Fighting the OutOfMemoryError

there are quite a few bloks.

maybe you could merge them to bigger blocks ?

Hmm… You’re using SharedNode right?



Also take a look at this, it might help for what you’re doing even though it is a lonnnng thread:

http://www.jmonkeyengine.com/forum/index.php?topic=3362.0

I'm really new to this engine, so… nope, I"m not using SharedNode.  That topic looks very useful though, so thanks much!  Does anyone have any idea why that error appears though?

try with -Xmx1024m ?

Why is simple, jme is not able to clean up old geometry and other stuff lieing around completly. Mostly this wont be a problem though if u use the above command.

It may be a problem with garbage collecting (since I crash the gc if I try to run it manually), but since I'm not dereferencing my objects, they shouldn't be collected anyways.



With -Xmx1024m replacing my 256m, my program is only able to generate ~38,000 / 163,840 blocks, whereas the 256m allows my program to create ~80,000.


38071/163840 900522024
38072/163840 900522024
38073/163840 900522024
38074/163840 900522024
38075/163840 900522024
38076/163840 900522024
38077/163840 900522024
38078/163840 900522024
Exception in thread "main" java.lang.OutOfMemoryError
   at sun.misc.Unsafe.allocateMemory(Native Method)
   at java.nio.DirectByteBuffer.<init>(Unknown Source)
   at java.nio.ByteBuffer.allocateDirect(Unknown Source)
   at com.jme.util.geom.BufferUtils.createFloatBuffer(BufferUtils.java:731)
   at com.jme.util.geom.BufferUtils.createVector2Buffer(BufferUtils.java:445)
   at com.jme.scene.shape.Box.duUpdateGeometryTextures(Box.java:153)
   at com.jme.scene.shape.AbstractBox.updateGeometry(AbstractBox.java:155)
   at com.jme.scene.shape.AbstractBox.updateGeometry(AbstractBox.java:175)
   at com.jme.scene.shape.Box.<init>(Box.java:108)
   at environment.Block.<init>(Block.java:14)
   at environment.World.renderHeightMap(World.java:129)
   at environment.World.build(World.java:79)
   at environment.World.<init>(World.java:57)
   at main.Entry.main(Entry.java:7)
Mar 31, 2010 6:54:56 AM com.jmex.game.DefaultUncaughtExceptionHandler uncaughtException
SEVERE: Main game loop broken by uncaught exception
java.lang.OutOfMemoryError
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClassCond(Unknown Source)
   at java.lang.ClassLoader.defineClass(Unknown Source)
   at java.security.SecureClassLoader.defineClass(Unknown Source)
   at java.net.URLClassLoader.defineClass(Unknown Source)
   at java.net.URLClassLoader.access$000(Unknown Source)
   at java.net.URLClassLoader$1.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at org.lwjgl.opengl.WindowsKeyboard.handleKey(WindowsKeyboard.java:157)
   at org.lwjgl.opengl.WindowsDisplay.handleKeyButton(WindowsDisplay.java:737)
   at org.lwjgl.opengl.WindowsDisplay.doHandleMessage(WindowsDisplay.java:867)
   at org.lwjgl.opengl.WindowsDisplay.handleMessage(WindowsDisplay.java:756)
   at org.lwjgl.opengl.WindowsDisplay.nUpdate(Native Method)
   at org.lwjgl.opengl.WindowsDisplay.update(WindowsDisplay.java:410)
   at org.lwjgl.opengl.Display.processMessages(Display.java:628)
   at org.lwjgl.opengl.Display.update(Display.java:660)
   at com.jme.renderer.lwjgl.LWJGLRenderer.displayBackBuffer(LWJGLRenderer.java:532)
   at com.jmex.game.StandardGame.run(StandardGame.java:252)
   at java.lang.Thread.run(Unknown Source)



I forgot to mention earlier, but this code only runs one time. At this point I am simply generating the world that I will later modify. My problem is running out of memory when the JVM thinks it still has memory left. This last run (with the 1024m) is a good example of the problem, since at the time of crash, Runtime.getRuntime().freeMemory() = 900522024 (bytes).

ever thought about using sharednodes sharedmeshs?



You are  runing out of direct memory, ther is another command to increas that xmx Xms somewhat like look in the java doc. Alternativ but slower, there is a way to disable the bytebuffer to use direct memory and let them use heap insteand when I rmember right.