Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By Norm

Thread: Out of Memory Error???

  1. #1
    pfolder is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Out of Memory Error???

    So, I've been trying to make a game with lwjgl, and have been using slick for the textures and texture loaders. For some reason, whenever I start up the game and it goes for maybe thirty seconds, it doesn't respond, and then terminates itself, giving the error:
    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 org.lwjgl.BufferUtils.createByteBuffer(BufferUtils .java:60)
    at org.newdawn.slick.opengl.PNGImageData.loadImage(PN GImageData.java:692)
    at org.newdawn.slick.opengl.CompositeImageData.loadIm age(CompositeImageData.java:62)
    at org.newdawn.slick.opengl.CompositeImageData.loadIm age(CompositeImageData.java:43)
    at org.newdawn.slick.opengl.InternalTextureLoader.get Texture(InternalTextureLoader.java:277)
    at org.newdawn.slick.opengl.InternalTextureLoader.get Texture(InternalTextureLoader.java:231)
    at org.newdawn.slick.opengl.InternalTextureLoader.get Texture(InternalTextureLoader.java:184)
    at org.newdawn.slick.opengl.TextureLoader.getTexture( TextureLoader.java:64)
    at org.newdawn.slick.opengl.TextureLoader.getTexture( TextureLoader.java:24)
    at graphicsgame.RenderMap.setMap(RenderMap.java:21)
    at graphicsgame.RenderScreen.renderState(RenderScreen .java:169)
    at graphicsgame.RenderScreen.update(RenderScreen.java :55)
    at graphicsgame.RenderScreen.start(RenderScreen.java: 33)
    at graphicsgame.GraphicsGame.main(GraphicsGame.java:8 )

    It isn't the problem with the amount of memory i have because i can play stuff like minecraft which uses a ton, and that works just fine. The way that I've been loading the textures so far is like this:
    try {
    zombie = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/zombie.png")));
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    and that's where the exact error in the lines come up. Any ideas?
    Thanks
    -Pfolder

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default Re: Out of Memory Error???

    Try doing some debugging to see what is using up memory. The Runtime class has some methods that return memory amounts. Try printing some of them in different parts of the code.
    Use the java command's -XProf option to get a trace of what code is executing. You may need to add some special code to exit the program before it throws the exception.
    Tolls likes this.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Out of Memory Error???

    The Minecraft launcher will define how mch memory it needs (using an -Xmx switch).
    If you don't use that then the fact Minecraft works is irrelevant to your problem, which is entirely down to the amount of memory Java has available to it and the amount you are asking it to use.
    Now, that is not to say you don't have a memory leak.

    Are you loading a lot of images?
    Is this the only image you are loading?
    Are you holding onto multiple copies of the same image, when you possibly only need the one?

    All these need to be looked into by you.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. out of memory error
    By aahadqj in forum Threads and Synchronization
    Replies: 5
    Last Post: 12-07-2010, 03:40 PM
  2. java out of memory error-heap space error
    By elsanthosh in forum NetBeans
    Replies: 4
    Last Post: 06-15-2010, 09:31 AM
  3. Out of memory Error
    By monika in forum Advanced Java
    Replies: 10
    Last Post: 03-16-2010, 05:03 PM
  4. Out of memory error
    By Mrs. Deswal in forum Threads and Synchronization
    Replies: 3
    Last Post: 07-30-2009, 03:27 AM
  5. Low memory error
    By rlhs76 in forum New To Java
    Replies: 2
    Last Post: 02-08-2008, 10:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •