Java.lang.OutOfMemoryError: Direct buffer memory

I get this after inserting to many textures.


java.lang.OutOfMemoryError: Direct buffer memory
        at java.nio.Bits.reserveMemory(Bits.java:632)
        at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:95)
        at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:288)
        at com.jme.util.TextureManager.loadImage(Unknown Source)
        at com.jme.util.TextureManager.loadTexture(Unknown Source)
        at rik.jme.control.PictureController.positionPicked(PictureController.java:94)
        at rik.jme.control.FirstPersonCameraController.firePositionPickedEvent(FirstPersonCameraController.java:318)
        at rik.jme.control.FirstPersonCameraController.performPick(FirstPersonCameraController.java:297)
        at rik.jme.control.FirstPersonCameraController.onButton(FirstPersonCameraController.java:160)
        at com.jme.input.lwjgl.LWJGLMouseInput.update(Unknown Source)
        at com.jme.input.InputSystem.update(Unknown Source)
        at com.jme.app.BaseGame.start(Unknown Source)
        at rik.jme.firstpersonbuilder.FirstPersonBuilder.<init>(FirstPersonBuilder.java:94)
        at rik.jme.firstpersonbuilder.FPB.main(FPB.java:23)



Is there a way to get around this besides decreasing texture size? Like increasing the memory or something?

Yeah, increase your maximum memory usage for the VM. :-p



darkfrog

Sorry that was a poorly formulated question. I was hoping there was some smart way to optimize heavy texture usage. Something like what was mentioned in a previous topic:

There have been a lot of recent changes, for example those that greatly improve the FPS for scenes with static geometry (that should do great for the "room" scene you have there, check out the new lock functions in the latest CVS), or lot's of texturing (sort of looks like you're only using 1 texture right now, when you'll add more and more this will benifit you automatically). These are relativly new and might have some bugs even, but they're there to stay.

That's about speed, not memory usage.



For optimizing memory usages, the most important thing is to make sure you are actually reusing your textures.



Another thing that I believe would help is converting your textures to DDS. Your files might become a bit bigger than for example JPEG, but the compression DDS uses applies not just to the file, but also once it's loaded into RAM and onto the videocard. As opposed to most formats like JPEG, which will be decoded to plain RGB(A) and stored in memory like that. However, not all of the compression methods of DDS are supported on (older) videocards, and jME supports only DXT1A, DXT1, DXT3 and DXT5 for textures.



Keep in mind that what darkfrog says is very true though. The standard VM size is rather small for a game.