Problems with Heap-Overflow

Hi,



I have a problem with my application. At first I have to say, that I'm not an expert in Java, but I hope some of you can help me.



I've created a virtual lab in Blender and exported it as an xml-File and loaded it to jME. This works pretty good, but when I want to load a picture as a texture on an imported plane (this should be a window of the lab) I get an exception:



22-Mar-2007 11:33:00 com.jme.scene.state.lwjgl.LWJGLTextureState load

WARNING: Attempted to apply texture with size that is not power of 2: 800 x 600

22-Mar-2007 11:33:00 com.jme.scene.state.lwjgl.LWJGLTextureState load

WARNING: Rescaling image to 1024 x 512 !!!

22-Mar-2007 11:33:01 com.jme.scene.state.lwjgl.LWJGLTextureState load

WARNING: Attempted to apply texture with size that is not power of 2: 2048 x 1536

22-Mar-2007 11:33:01 com.jme.scene.state.lwjgl.LWJGLTextureState load

WARNING: Rescaling image to 2048 x 2048 !!!

java.lang.OutOfMemoryError: Java heap space



I don't know why this exception comes, because on a similar PC with the same hard- and software it works.



I'm using JSK 1.6 and Eclipse 3.2 as the compiler. I've already tried to increase the heap in Eclipse with "-vmargs -Xms1512m -Xmx1512m" but it doesn't change anything.



here is my code:



import java.io.BufferedInputStream;

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.net.URL;

import com.jme.app.SimpleGame;

import com.jme.scene.Node;

import com.jme.scene.state.TextureState;

import com.jme.image.Texture;

import com.jme.math.Vector3f;

import com.jme.util.TextureManager;

import com.jmex.model.XMLparser.JmeBinaryReader;

import com.jmex.model.XMLparser.JmeBinaryWriter;

import com.jmex.model.XMLparser.XMLtoBinary;

import com.jmex.model.util.ModelLoader;

import com.jme.scene.state.LightState;

import com.jme.light.PointLight;

import com.jme.renderer.ColorRGBA;

import com.jme.bounding.BoundingBox;

//



public class LaborXML extends SimpleGame{
protected LightState lightState;

public static void main(String[] args) {
LaborXML app = new LaborXML();
    app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
    app.start();
}
//
 


protected void simpleInitGame() {
  //System.out.println("In the simple init game method");
  //display.setTitle("Test");


//
 

//Lights
  // Set up a basic, default light
  PointLight light = new PointLight();
  light.setDiffuse( new ColorRGBA( 0.75f, 0.75f, 0.75f, 0.75f ) );
  light.setAmbient( new ColorRGBA( 0.5f, 0.5f, 0.5f, 1.0f ) );
  light.setLocation( new Vector3f( 4, 4, 4 ) );
  light.setEnabled( true );
     
  //Attach the light to a lightState and the lightState to rootNode
  lightState = display.getRenderer().createLightState();
  lightState.setEnabled( true );
  lightState.attach( light );
  rootNode.setRenderState( lightState );
 
  cam.setLocation(new Vector3f(4,2,6));
    cam.update();

//
 

   
    try {
 
  //Initialise binary converter
  XMLtoBinary converter = new XMLtoBinary();
 
  //Initialise binary reader
  JmeBinaryReader jbr = new JmeBinaryReader();
 
  //Initialise binary writer
  JmeBinaryWriter jbw = new JmeBinaryWriter();
 
//
 
 
  // convert the input file to a jme-binary "LabNoExtra"
  ByteArrayOutputStream LabNoExtra = new ByteArrayOutputStream();
  URL LabModel = ModelLoader.class.getClassLoader().getResource("labnoextra2.xml");
  converter.sendXMLtoBinary(new BufferedInputStream(LabModel.openStream()), LabNoExtra);
 
  //get the "LabNoExtra"
  Node lab = jbr.loadBinaryFormat(new ByteArrayInputStream(LabNoExtra.toByteArray()));
   
  // write the "LabNoExtra"
  ByteArrayOutputStream BO2 = new ByteArrayOutputStream();
  jbw.writeScene(lab,BO2);
       
  // Send the new jME binary to a jME SceneGraph and attach it.
  lab = jbr.loadBinaryFormat(new ByteArrayInputStream(BO2.toByteArray()));
   
  // attach our LabNoExtra to the scene grap
  rootNode.attachChild(lab);
 
//
 
 
  //convert the input file to a jme-binary "MediaPlayer"
  ByteArrayOutputStream MediaPlayer = new ByteArrayOutputStream();
  URL MediaPlayerModel = ModelLoader.class.getClassLoader().getResource("dvd.xml");
  converter.sendXMLtoBinary(new BufferedInputStream(MediaPlayerModel.openStream()), MediaPlayer);
       
  //get the "MediaPlayer"
  Node media = jbr.loadBinaryFormat(new ByteArrayInputStream(MediaPlayer.toByteArray()));
       
  //write the "MediaPlayer"
  ByteArrayOutputStream BO3 = new ByteArrayOutputStream();
  jbw.writeScene(media,BO3);
 
  //Send the new jME binary to a jME SceneGraph and attach it.
  media = jbr.loadBinaryFormat(new ByteArrayInputStream(BO3.toByteArray()));
   
  // attach our MediaPlayer to the scene grap
  rootNode.attachChild(media);
 
//
 
 
  //convert the input file to a jme-binary "TV"
  ByteArrayOutputStream TV = new ByteArrayOutputStream();
  URL TVModel = ModelLoader.class.getClassLoader().getResource("tv.xml");
  converter.sendXMLtoBinary(new BufferedInputStream(TVModel.openStream()), TV);
       
  //get the "TV"
  Node tvscreen = jbr.loadBinaryFormat(new ByteArrayInputStream(TV.toByteArray()));
       
  //write the "TV"
  ByteArrayOutputStream BO4 = new ByteArrayOutputStream();
  jbw.writeScene(tvscreen,BO4);
 
  //Send the new jME binary to a jME SceneGraph and attach it.
  tvscreen = jbr.loadBinaryFormat(new ByteArrayInputStream(BO4.toByteArray()));
   
  // attach our TV to the scene grap
  rootNode.attachChild(tvscreen);
 
//
 
 
  //convert the input file to a jme-binary "Window"
  ByteArrayOutputStream Window = new ByteArrayOutputStream();
  URL WindowModel = ModelLoader.class.getClassLoader().getResource("window2.xml");
  converter.sendXMLtoBinary(new BufferedInputStream(WindowModel.openStream()), Window);
       
  //get the "Window"
  Node labwindow = jbr.loadBinaryFormat(new ByteArrayInputStream(Window.toByteArray()));
         
  //write the "Window"
  ByteArrayOutputStream BO5 = new ByteArrayOutputStream();
  jbw.writeScene(labwindow,BO5);
 
  //Send the new jME binary to a jME SceneGraph and attach it.
  labwindow = jbr.loadBinaryFormat(new ByteArrayInputStream(BO5.toByteArray()));
   
  // attach our Window to the scene grap
  //rootNode.attachChild(labwindow);
 
  labwindow.setModelBound(new BoundingBox());
  labwindow.updateModelBound();
 
  TextureState ts = display.getRenderer().createTextureState();
      ts.setEnabled(true);
      ts.setTexture(
          TextureManager.loadTexture(
          LaborXML.class.getClassLoader().getResource(
          "landscape.jpg"),
          Texture.MM_LINEAR_LINEAR,
          Texture.FM_LINEAR));

    // rootNode.setRenderState(ts);
    rootNode.attachChild(labwindow);
//
 
  }catch (IOException e){
  System.out.println("Couldn't load the input file:" + e);
  e.printStackTrace();}
  catch (java.lang.NullPointerException npe ) {
    npe.printStackTrace();
  }
}

}

Thanks for every helpfull answers.

Try reducing the size of your image and see if that fixes it. :wink:

Thanks, I've done it and it works. But it's a little bit strange because on one PC it runs and on another which has the same properties it causes an exception. :expressionless:



Nevertheless… thanks a lot.

There are a lot of factors that can cause that.  Memory availability I would expect would be the biggest potential cause.



If you need larger textures I believe the best way to do it (and I'm sure I will be corrected if this is not right) is to create smaller textures and connect them together.

I'm not sure how that could help, df.



But you should avoid that rescaling with large texture, Mexxchen - provide your texture e.g. in 2048x2048

I was under the impression that the most memory consumption was done when it it processing the image into video memory and if you did it in smaller chunks it would be less likely to throw a memory error?  Or maybe I'm just in the middle of a pond without a lily pad… 

Try using -vmargs -Xms512m -Xmx768m -XX:PermSize=128m -XX:MaxPermSize=256m

Hi,



I've resized the picture, but there is still a warning, where Eclipse tries to rescale the picture. Is it possible that java can handle only quadratic pics? Do I have to use other methods to use non-quadratic pics?

Most graphic cards, especially older ones can only handle power of 2 textures, e.g. 512 x 256, 1024 x 1024 etc.