I’m having trouble tracking down why memory usage is so high and I keep getting a direct buffer memory error. Before we start here is the relevant output.
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.OutOfMemoryError: Direct buffer memory
at java.nio.Bits.reserveMemory(Bits.java:693)
at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:123)
at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:311)
at com.jme3.util.BufferUtils.createByteBuffer(BufferUtils.java:997)
at com.jme3.texture.plugins.AWTLoader.load(AWTLoader.java:155)
at com.jpony.UI.Control.setImage(Control.java:394)
at com.jpony.UI.Label.draw(Label.java:138)
at com.jpony.UI.Label.setSize(Label.java:181)
at com.jpony.UI.Control.resize(Control.java:376)
at com.jpony.UI.UserInterface.resize(UserInterface.java:264)
at com.jpony.UI.UserInterfaceManager.resize(UserInterfaceManager.java:103)
at myGame.Game.loadHud(Game.java:157)
at myGame.Game.initialize(Game.java:140)
at myGame.Game.<init>(Game.java:81)
at myGame.LoadGame.update(LoadGame.java:50)
at com.jme3.app.state.AppStateManager.update(AppStateManager.java:287)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:236)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:193)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
at java.lang.Thread.run(Thread.java:745)
It is important to note that is crashing on texture load and it doesn’t always crash in the same spot. The terrain textures seem to be another reason for the crash but I’ll come back to the terrain in a bit.
When I first got the direct buffer memory error it was after modifying my scene. I added one sphere in my scene , ran it , then it crashed. I tried deleting the sphere then running the application but I got the same memory error.
I loaded up my last good scene save then ran the application and it worked fine. I tried adding another sphere and I got the same error. The same as last time removing the sphere did not fix the problem.
I noticed the terrain texture where causing the error so I removed the terrain from the file then ran the app and it worked fine.
My next step I decided to run a memory test on both files the original and the file without the terrain here are my results.
with terrain
initial launch = 35 - 40 mb
title screen = 350 - 450 mb
game = 800 - 1000 mb
with out terrain
initial launch = 35 - 40 mb
title screen = 350 - 450 mb
game = 500 - 600 mb
What is very noticeable is that my title screen has a 400mb foot print. The title screen consist of one low poly model , one low poly animation and one very simple terrain 32x8. The total size of all the models and textures in my project come to about 150mb. A scene with only 3 objects shouldn’t be running with a memory foot print of 400+mb.
The second most noticeable thing is the about 400mb drop in memory usage that comes from removing the terrain.
My terrain uses 5 textures with a 2048x2048 size. They are in tga format and the actual file size around 2mb. I also have a 36mb tga file that is a texture atlas for all of my models. However the atlas has yet to cause a crash. My best guess is this has something to do with the textures.
I tried running the argument -Xmx128m and gradually increasing the size. Anything 1024 or above was crashing the application on launch.
Finally I did one last test.
I ran the working file several times and let it run about 30 minutes each. I noticed after about 10 - 15 minutes into the runt he memory would drop down to around 150 - 250 mb which is a much more reasonable level for the file size.
My biggest question is what could be causing the application to take up so much memory after loading a simple file ?
My second question is does anyone have any suggestions for helping with the direct buffer memory error.