NullPointerException on (pre)loading skybox

Hello everyone!

I have a problem with creating my skybox. I load it with the following code:

    * Generates a skybox from six files (North,South,West,East,Down,Up).<br>
    * Example: location=<i>data/textures/skybox1.jpg</i><br>
    * For this location the following textures will be used for creating the skybox:<br>
    * <i>skybox1_north.jpg, skybox1_south.jpg, skybox1_west.jpg, ...</i>
    * @param location filename giving dir and format of the skybox textures
    * @return a valid skybox or null
   public static Skybox getSkybox(String location) {
      String parts1[] = location.split("/");
      String filename = parts1[parts1.length-1];
      int dotPos = filename.lastIndexOf(".");
      int slashPos = location.lastIndexOf("/");
      String dir = location.substring(0,slashPos+1);
      String name = filename.substring(0, dotPos);
      String type = filename.substring(dotPos);         
      Skybox skybox = new Skybox("Skybox "+name, 500, 500, 500);      
      skybox.setTexture(Skybox.NORTH, getTextureFromFile(dir+name+"_north"+type));
      skybox.setTexture(Skybox.SOUTH, getTextureFromFile(dir+name+"_south"+type));
      skybox.setTexture(Skybox.WEST, getTextureFromFile(dir+name+"_west"+type));
      skybox.setTexture(Skybox.EAST, getTextureFromFile(dir+name+"_east"+type));
      skybox.setTexture(Skybox.DOWN, getTextureFromFile(dir+name+"_down"+type));
      skybox.setTexture(Skybox.UP, getTextureFromFile(dir+name+"_up"+type));
      return skybox;

The method getTextureFromFile does nothing more than to call TextureManager.loadTexture with a bit of exception handling and stuff.
If i load the textures for each side seperately i they work (i can put them to RenderStates and apply them to any object).

However, preloadTextures causes an exception:

Exception in thread "main" java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glHint(
at com.jme.scene.state.lwjgl.LWJGLTextureState.apply(
at com.jme.scene.Skybox.preloadTextures(
at de.spacemonkeys.util.Util.getSkybox(
at de.spacemonkeys.Demo.<init>(
at de.spacemonkeys.Main.main(

I see where the problem is, but don't understand why it is there. Can anyone help?

Oh and i noticed something.

When i don't call preloadTextures and updateRenderState the Skybox displays properly.

However, another exception then appears as i adjust the skybox's position:

20.09.2007 12:28:27 uncaughtException
SCHWERWIEGEND: Main game loop broken by uncaught exception
at de.spacemonkeys.Demo.update(
at Source)

   public void update(float tpf) {
      if(input != null) input.update(tpf);
      rootNode.updateGeometricState(tpf, true);
      if(KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) System.exit(0);

I guess that should tell me something, but it doesn't. I don't get it.

are you using StandardGame and GameStates ?

if so, then preloadTextures () needs to be sent to the Game GametaskQueueManager because it calls a OpenGL function.

        Callable<?> preload = new Callable() {
            public Object call() throws Exception {
                return null;

Yup that's it. Thank you very much!  :slight_smile: