Water in GameState - NullPointerException

Hi everyone…



I am currently trying to integrate the WaterEffectRenderPass into my InGameState which extends the PhysicsGameState:


public InGameState(final String name, final TransitionGameState trans) {
        super(name);

        cam = DisplaySystem.getDisplaySystem().getRenderer().getCamera();
         disp = DisplaySystem.getDisplaySystem();
          //timer = Timer.getTimer();

       initGame();
       }
   
    private void initGame(){
   
        initCam();
   initWater();
       
             
        rootNode.updateRenderState();
        rootNode.updateGeometricState(0, true);     

    }
   


    /**
     * Set the background color to Black.
     * Hide the mouse cursor.
     * @param active GameState aktiv Yes/no
     */
    @Override
    public final void setActive(final boolean active) {
        super.setActive(active);
        if (!active) {
           return;
        }
       
        GameTaskQueueManager.getManager().update(new Callable<Object>() {
            public Object call() throws Exception {
                Game.getInstance().resume();
                return null;
            }
        });
       
        // disable mouse cursor
        MouseInput.get().setCursorVisible(false);

            
        Timer.getTimer().reset();
        Callable<Object> exe = new Callable<Object>() {
            public Object call() {
                disp.getRenderer().setBackgroundColor(ColorRGBA.black);
                return null;
            }
        };
        GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER)
                .enqueue(exe);
    }
   
    /**
     * the update Method gets called once per Frame.
     * Spawn Random Asteroids with the Earth as target.
     * Updates the position of the skybox/stardust.
     * Updates the chasecam.
     *
     * @param tpf time since last frame in ms.
     */
    @Override
    public final void update(float tpf) {
       if (Game.getInstance().isPaused()) {
          tpf = 0;
       }
   
        input.update(tpf);
        chaser.update(tpf);
        System.out.println(player.getLocalTranslation());
       
    //    skybox.getLocalTranslation().set( cam.getLocation() );
       
        Vector3f transVec = new Vector3f(cam.getLocation().x,
                waterEffectRenderPass.getWaterHeight(), cam.getLocation().z);
        setTextureCoords(0, transVec.x, -transVec.z, textureScale);
        setVertexCoords(transVec.x, transVec.y, transVec.z);
      
        rootNode.updateGeometricState(tpf, true);
       
    }
   
    /**
     * Render the Scene and draw the HUD.
     */
    @Override
    public void render(float tpf) {
       if (Game.getInstance().isPaused()) {
          tpf = 0;
       }
       super.render(tpf);
    }
   
   
   private void initCam(){
      cam.setFrustumPerspective(45.0f, (float) disp.getWidth()
                / (float) disp.getHeight(), 1f, farPlane);
        cam.setLocation(new Vector3f(-320, 80, -270));
        cam.lookAt(new Vector3f(0, 0, 0), Vector3f.UNIT_Y);
        cam.update();
   }

   private void initWater(){
      waterEffectRenderPass = new WaterRenderPass(cam, 6, false, true);
        waterEffectRenderPass.setWaterPlane(new Plane(new Vector3f(0.0f, 1.0f,
                0.0f), 0.0f));
        waterEffectRenderPass.setClipBias(-1.0f);
        waterEffectRenderPass.setReflectionThrottle(0.0f);
        waterEffectRenderPass.setRefractionThrottle(0.0f);

        waterQuad = new Quad("waterQuad", 1, 1);
        FloatBuffer normBuf = waterQuad.getNormalBuffer(0);
        normBuf.clear();
        normBuf.put(0).put(1).put(0);
        normBuf.put(0).put(1).put(0);
        normBuf.put(0).put(1).put(0);
        normBuf.put(0).put(1).put(0);

        waterEffectRenderPass.setWaterEffectOnSpatial(waterQuad);
        rootNode.attachChild(waterQuad);

        waterEffectRenderPass.setReflectedScene(skybox);
    //    waterEffectRenderPass.addReflectedScene(reflectionTerrain);
        waterEffectRenderPass.setSkybox(skybox);
        pManager.add(waterEffectRenderPass);

        RenderPass rootPass = new RenderPass();
        rootPass.add(rootNode);
        pManager.add(rootPass);
       
        Node fpsNode = new Node("fpsNode");
        RenderPass fpsPass = new RenderPass();
        fpsPass.add(fpsNode);
        pManager.add(fpsPass);

        rootNode.setCullMode(SceneElement.CULL_NEVER);
   }

   private void setTextureCoords(int buffer, float x, float y,
               float textureScale) {
           x *= textureScale * 0.5f;
           y *= textureScale * 0.5f;
           textureScale = farPlane * textureScale;
           FloatBuffer texBuf;
           texBuf = waterQuad.getTextureBuffer(0, buffer);
           texBuf.clear();
           texBuf.put(x).put(textureScale + y);
           texBuf.put(x).put(y);
           texBuf.put(textureScale + x).put(y);
           texBuf.put(textureScale + x).put(textureScale + y);
       }

   private void setVertexCoords(float x, float y, float z) {
           FloatBuffer vertBuf = waterQuad.getVertexBuffer(0);
           vertBuf.clear();

           vertBuf.put(x - farPlane).put(y).put(z - farPlane);
           vertBuf.put(x - farPlane).put(y).put(z + farPlane);
           vertBuf.put(x + farPlane).put(y).put(z + farPlane);
           vertBuf.put(x + farPlane).put(y).put(z - farPlane);
       }
}



I get the following error message:

23.04.2009 10:54:32 core.SDExceptionHandler uncaughtException
SCHWERWIEGEND: caucht uncaught exception, quitting game
23.04.2009 10:54:32 core.SDExceptionHandler uncaughtException
SCHWERWIEGEND: null
java.lang.NullPointerException
   at com.jme.scene.state.lwjgl.LWJGLShaderObjectsState.isSupported(LWJGLShaderObjectsState.java:122)
   at com.jme.scene.state.lwjgl.LWJGLShaderObjectsState.<init>(LWJGLShaderObjectsState.java:88)
   at com.jme.renderer.lwjgl.LWJGLRenderer.createGLSLShaderObjectsState(LWJGLRenderer.java:380)
   at com.jmex.effects.water.WaterRenderPass.initialize(WaterRenderPass.java:187)
   at com.jmex.effects.water.WaterRenderPass.<init>(WaterRenderPass.java:175)
   at gamestates.InGameState.initWater(InGameState.java:355)
   at gamestates.InGameState.initGame(InGameState.java:138)
   at gamestates.InGameState.<init>(InGameState.java:119)
   at core.Start.main(Start.java:94)



Did anybody had the same problem and can help with out here?

Thanks RapidM

Do you create the water in an OpenGL thread ?

I forgot that  :roll:



Now I added:


 Future<WaterRenderPass> future = GameTaskQueueManager.getManager().update(new Callable<WaterRenderPass>() {
            public WaterRenderPass call() throws Exception {
                   cam = DisplaySystem.getDisplaySystem().getRenderer().getCamera();
                   waterEffectRenderPass = new WaterRenderPass(cam, 4, false, true);
                    return waterEffectRenderPass;
            }
        });
        try {
         WaterRenderPass waterEffectRenderPass = future.get();
      } catch (InterruptedException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (ExecutionException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }



But it still gives me the error postet below at the line :

waterEffectRenderPass = new WaterRenderPass(cam, 6, false, true);


Is my threadcall wrong?

I wonder if your video card doesn't support shaders, try passing a false in for the refraction also…

ex: new WaterRenderPass(cam, 4, false, false);





Looking at the code though, it seems this call is made at line 196 here:

waterShader = display.getRenderer().createGLSLShaderObjectsState();



I wonder why you are getting an error at line 187...
basixs said:

I wonder if your video card doesn't support shaders, try passing a false in for the refraction also...
ex: new WaterRenderPass(cam, 4, false, false);


Looking at the code though, it seems this call is made at line 196 here:

waterShader = display.getRenderer().createGLSLShaderObjectsState();



I wonder why you are getting an error at line 187...


Better yet RapidM, try your code on some machines with different video cards.