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));
      skybox.preloadTextures();
      
      skybox.updateRenderState();
      
      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(GL11.java:1508)
at com.jme.scene.state.lwjgl.LWJGLTextureState.apply(LWJGLTextureState.java:418)
at com.jme.scene.Skybox.preloadTextures(Skybox.java:271)
at de.spacemonkeys.util.Util.getSkybox(Util.java:107)
at de.spacemonkeys.Demo.<init>(Demo.java:37)
at de.spacemonkeys.Main.main(Main.java:31)


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 com.jmex.game.DefaultUncaughtExceptionHandler uncaughtException
SCHWERWIEGEND: Main game loop broken by uncaught exception
java.lang.NullPointerException
at de.spacemonkeys.Demo.update(Demo.java:48)
at com.jmex.game.state.GameStateNode.update(GameStateNode.java:71)
at com.jmex.game.StandardGame.update(StandardGame.java:299)
at com.jmex.game.StandardGame.run(StandardGame.java:188)
at java.lang.Thread.run(Unknown Source)



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



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 {
                preloadTextures();
                return null;
            }
        };
        GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER)
                .enqueue(preload);

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