Game Error

6 replies [Last post]
Offline
Joined: 01/08/2011

When my game goes into the game end (win) or game end (lose) loops (which are inside the main game loop) I get this error:


java.lang.OutOfMemoryError: Direct buffer memory
 at java.nio.Bits.reserveMemory(Bits.java:633)
 at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:95)
 at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:288)
 at com.jme3.util.BufferUtils.createByteBuffer(BufferUtils.java:908)
 at com.jme3.texture.plugins.AWTLoader.load(AWTLoader.java:163)
 at com.jme3.texture.plugins.AWTLoader.load(AWTLoader.java:191)
 at com.jme3.texture.plugins.AWTLoader.load(AWTLoader.java:201)
 at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:273)
 at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:325)
 at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:344)
 at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:356)
 at env3d.GameObjectAdapter.update(GameObjectAdapter.java:167)
 at env3d.Env.update(Env.java:948)
 at env3d.advanced.EnvAdvanced.update(EnvAdvanced.java:128)
 at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)
 at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)
 at env3d.Env.advanceOneFrame(Env.java:864)
 at env3d.Env.advanceOneFrame(Env.java:854)
 at Game.play(Game.java:214)
 


Its fine while the game is playing, its only when the game ends it does this. Am I taxing the env3d resources too much?

Offline
Joined: 01/08/2011
game error not fixed

I guess I need to clean up my code a bit

Offline
Joined: 12/13/2010
How big is your terrain? 

How big is your terrain?  That could be a problem with memory.

Offline
Joined: 01/08/2011
OutOfMemoryError: Direct buffer memory problem continues

I am using the default terrain (termap1.png - 256 x 256). however I have a water object occupying the map terrain below y = 19 (the depression in the map). The game runs fine until one of the game end loops happen; as soon as env.advanceOneFrame is called the direct buffer memory runs out. The associated soundloop which is called before env.advanceOneFrame will play though. The game end loops are simple animations with a soundloop playing. Tux either spins around and hops up and down with cheering (win), or lies dead on the ground with the camera rotating on the y-axis above him with booing (lose). I have tried to keep the list processing and itteration down as much as I can in the main game loop, but even when I decrese the number of objects in the game it still craps out as soon as the end game loop starts; nothing seems to work. Should I simplify the game in order to conserve buffer memory (although I doubt that it would make a difference since it only happens when game end loop starts) ? As soon as I can resolve this last issue I can submit the game for others to try. Here are my game end loops:


 


// Starts the appropriate game over loop depending upon weather tux survives or not.
        if (gameOver == true) {
            int counter = 0;
            env.soundStop("sounds/Hey Girls, Hey Boys.wav");
            env.soundStop("sounds/eyeDeath.wav");
            env.soundStop("sounds/eyeShake.wav");
            env.soundStop("sounds/machineGun.wav");
            env.soundStop("sounds/shotgun.wav");
            env.soundStop("sounds/shot.wav");
            env.soundStop("sounds/hit.wav");
            env.soundStop("sounds/drowning.wav");
            env.setDisplayStr("", 90, 475);
            tux.setScale(1);
            tux.setRotateY(180);
            if (tux.getHealth() > 0) {
                tux.setTexture("models/tux/tux_happy.png");
                tux.setXYZ(-36,52,-31);
                while (env.getKey() != 1) {
                    counter++;
                    env.setDisplayStr("You Live!      Score: " + score, 150, 450, 2, 0, 1, 0, 1);
                    env.soundLoop("sounds/cheer.wav");
                    env.setCameraXYZ(-36,62,-41);
                    env.setCameraYaw(180);
                    env.setCameraPitch(-40);
                    tux.setRotateY(tux.getRotateY() + 12);
                    if (counter < 16) {
                        tux.setY(tux.getY() + .2);
                    } else {
                        tux.setY(tux.getY() - .2);
                    }
                    if (counter >= 30) {
                        counter = 0;
                    }
                    env.advanceOneFrame();
                }
                env.exit();
            }
            if (tux.getHealth() <= 0) {
                tux.setTexture("models/tux/tux_dead.png");
                tux.setRotateX(-90);
                tux.setY(tux.getY()-1);
                while (env.getKey() != 1) {
                    env.setDisplayStr("Your Dead!      Score: " + score, 150, 450, 2, 1, 0, 0, 1);
                    env.soundLoop("sounds/Boo.wav");
                    env.setCameraYaw(env.getCameraYaw()+1);
                    env.setCameraPitch(-89);
                    env.setCameraXYZ(tux.getX(),tux.getY()+5,tux.getZ());
                    env.advanceOneFrame();
                }
                env.exit();
            }
        }

Offline
Joined: 12/13/2010
Put the soundLoop call

Put the soundLoop call OUTSIDE of the loops.  What you are doing here is calling soundLoop repeatedly which will cause a memory error.  Call soundLoop before the start of the while loop.

 

Offline
Joined: 01/08/2011
java.lang.OutOfMemoryError: Direct buffer memory, continues...

I modified the game end loops to put the soundloop call outside of the while loops and checked the rest of the program for any other runaway loops. The frame rate can drop to around 11 or 12 fps at times during game play but is usually around 25. The game itself runs fine, it's only when one of the game end loops start the memory runs out when env.advanceOneFrame is called. I checked the frame rate on the game end loops and it is around 25 for game win loop and 45 for game loose loop. I am perplexed as to what could be causing the problem. As far as I can tell there are no other runaway loops or unnecessary itteration, but I will continue to test the program. Below are the modified game end loops and the error message that appears on the terminal window:


 


java.lang.OutOfMemoryError: Direct buffer memory
 at java.nio.Bits.reserveMemory(Bits.java:633)
 at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:95)
 at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:288)
 at com.jme3.util.BufferUtils.createByteBuffer(BufferUtils.java:908)
 at com.jme3.texture.plugins.AWTLoader.load(AWTLoader.java:163)
 at com.jme3.texture.plugins.AWTLoader.load(AWTLoader.java:191)
 at com.jme3.texture.plugins.AWTLoader.load(AWTLoader.java:201)
 at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:273)
 at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:325)
 at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:344)
 at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:356)
 at env3d.GameObjectAdapter.update(GameObjectAdapter.java:167)
 at env3d.Env.update(Env.java:948)
 at env3d.advanced.EnvAdvanced.update(EnvAdvanced.java:128)
 at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)
 at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)
 at env3d.Env.advanceOneFrame(Env.java:864)
 at env3d.Env.advanceOneFrame(Env.java:854)
 at Game.play(Game.java:417)


 


// Starts the appropriate game over loop depending upon weather tux survives or not.
        if (gameOver == true) {
            int counter = 0;
            env.soundStop("sounds/Hey Girls, Hey Boys.wav");
            env.soundStop("sounds/eyeDeath.wav");
            env.soundStop("sounds/eyeShake.wav");
            env.soundStop("sounds/machineGun.wav");
            env.soundStop("sounds/shotgun.wav");
            env.soundStop("sounds/shot.wav");
            env.soundStop("sounds/hit.wav");
            env.soundStop("sounds/drowning.wav");
            env.setDisplayStr("", 90, 475);
            tux.setScale(1);
            tux.setRotateY(180);
            if (tux.getHealth() > 0) {
                tux.setTexture("models/tux/tux_happy.png");
                tux.setXYZ(-36,52,-31);
                env.soundLoop("sounds/cheer.wav");
                env.setDisplayStr("You Live!      Score: " + score, 150, 450, 2, 0, 1, 0, 1);
                while (env.getKey() != 1) {
                    counter++;
                    env.setCameraXYZ(-36,62,-41);
                    env.setCameraYaw(180);
                    env.setCameraPitch(-40);
                    tux.setRotateY(tux.getRotateY() + 12);
                    if (counter < 16) {
                        tux.setY(tux.getY() + .2);
                    } else {
                        tux.setY(tux.getY() - .2);
                    }
                    if (counter >= 30) {
                        counter = 0;
                    }
                    env.advanceOneFrame();
                }
                env.exit();
            }
            if (tux.getHealth() <= 0) {
                tux.setTexture("models/tux/tux_dead.png");
                tux.setRotateX(-90);
                tux.setY(tux.getY()-1);
                env.soundLoop("sounds/Boo.wav");
                env.setDisplayStr("Your Dead!      Score: " + score, 150, 450, 2, 1, 0, 0, 1);
                while (env.getKey() != 1) {
                    env.setCameraYaw(env.getCameraYaw()+1);
                    env.setCameraPitch(-89);
                    env.setCameraXYZ(tux.getX(),tux.getY()+5,tux.getZ());
                    env.advanceOneFrame();
                }
                env.exit();
            }
        }

Offline
Joined: 01/08/2011
game error resolved sorta

After some code clean up and eliminating some objects, the game end loops now "seem" to run ok without running out the buffer memory. So the beta version of the game is ready to be uploaded; however, it appears that it may be too large to be uploaded to env3d becuase of the size of the game_support Executable Jar File (47 724 kb) since there is a limit of 20 mb for uploads. Are there any alternatives for making it accessible to others?