Failing at HeightMapping with a Skybox!

I'll attach my code (phail.txt).



I keep getting null pointer exceptions when I try to use sky.setTexture(n); and such. Check it out, it's quite odd. No clue why it isn't working. (All the URLs Load properly, otherwise they would just default to the regular texture).

can you reproduce the problem with a small test case?

Core-Dump said:

can you reproduce the problem with a small test case?

Not sure what you mean, but it looks like I didn't get the attachment in. Now I see I can't attach anything. Hahaha.

You can just post the source inside '[code'] tags if its not too much.



If you can reproduce the problem within a small SimpleGame test case, it would be easy for someone else to just copy paste it and run it himself to take a look at it.

And chances are good, that while trying to reproduce the problem, you will find the error yourself :slight_smile:



Make sure to always check the return values and see what method return null.


import com.jme.app.BaseGame;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import com.jme.bounding.BoundingSphere;
import com.jme.image.Texture;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.Skybox;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.CullState;
import com.jme.scene.state.FogState;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.TextureManager;
import com.jmex.terrain.TerrainBlock;
import com.jmex.terrain.util.RawHeightMap;
import java.net.URL;
import java.util.ArrayList;
import java.util.Vector;

/**
 *
 * @author Tyler
 */
public class GameClient extends BaseGame
{
    //Global Variables
    private boolean fullscreen = false; //For video settings
    private int width, height, depth, freq; //For video settings
   
    private Node myNode;
   
    Sphere myCharacter;
   
    Skybox mySky;
   
    RawHeightMap map;
   
    TerrainBlock world;
   
    FogState fog;
   
    public static void main(String args[])
    {
        GameClient app = new GameClient();
        app.setDialogBehaviour(FIRSTRUN_OR_NOCONFIGFILE_SHOW_PROPS_DIALOG);
        app.start();
    }
   
    @Override
    protected void update(float interpolation)
    {
        if(KeyBindingManager.getKeyBindingManager().isValidCommand("exit"))
        {
            System.exit(0);
        }
    }

    @Override
    protected void render(float interpolation)
    {
        display.getRenderer().clearBuffers();
        display.getRenderer().draw(myNode);
    }

    @Override
    protected void initSystem()
    {
        width = properties.getWidth();
        height = properties.getHeight();
        depth = properties.getDepth();
        freq = properties.getFreq();
        fullscreen = properties.getFullscreen();
       
        try
        {
            display = DisplaySystem.getDisplaySystem(properties.getRenderer());
            display.createWindow(width, height, depth, freq, fullscreen);
        }
        catch(JmeException e)
        {
            System.out.println("Your video settings are buggy.");
            System.exit(0);
        }
       
        KeyBindingManager.getKeyBindingManager().set("exit", KeyInput.KEY_ESCAPE);
    }

    @Override
    protected void initGame()
    {
       
        myNode = new Node();
        this.buildWorld();
        CullState cs = display.getRenderer().createCullState();
        cs.setCullMode(cs.CS_BACK);
        cs.setEnabled(true);
        myNode.setRenderState(cs);
       
        myCharacter = new Sphere("player", 30, 30, 2);
        myCharacter.setModelBound(new BoundingSphere());
        myCharacter.updateModelBound();
        myCharacter.setLocalTranslation(0,0,0);
        myNode.attachChild(myCharacter);
       
        mySky = new Skybox("sky", 10, 10, 10);
    }

    @Override
    protected void reinit()
    {
        display.recreateWindow(width, height, depth, freq, fullscreen);
    }

    @Override
    protected void cleanup()
    {
    }
   
    private void buildWorld()
    {
        URL mapLoc = GameClient.class.getClassLoader().getResource("world.raw");
        map = new RawHeightMap(mapLoc, 513, RawHeightMap.FORMAT_8BIT, false);
        Vector3f terrainScale = new Vector3f(1f,1f,1f);
        world= new TerrainBlock("world", map.getSize(), terrainScale, map.getHeightMap(), new Vector3f(0,0,0), false);
       
        myNode.attachChild(world);
       
        fog = display.getRenderer().createFogState();
        fog.setDensity(3.0f);
        fog.setStart(100f);
        fog.setEnd(350f);
        fog.setColor(ColorRGBA.lightGray);
        myNode.setRenderState(fog);
       
        Texture n, s, e, w, d, u;

        n = (TextureManager.loadTexture(GameClient.class.getClassLoader().getResource("images\1.jpg"), Texture.MM_LINEAR, Texture.FM_LINEAR));
        s = (TextureManager.loadTexture(GameClient.class.getClassLoader().getResource("images\2.jpg"), Texture.MM_LINEAR, Texture.FM_LINEAR));
        e = (TextureManager.loadTexture(GameClient.class.getClassLoader().getResource("images\3.jpg"), Texture.MM_LINEAR, Texture.FM_LINEAR));
        w = (TextureManager.loadTexture(GameClient.class.getClassLoader().getResource("images\4.jpg"), Texture.MM_LINEAR, Texture.FM_LINEAR));
        d = (TextureManager.loadTexture(GameClient.class.getClassLoader().getResource("images\5.jpg"), Texture.MM_LINEAR, Texture.FM_LINEAR));
        u = (TextureManager.loadTexture(GameClient.class.getClassLoader().getResource("images\6.jpg"), Texture.MM_LINEAR, Texture.FM_LINEAR));
       
        mySky.setTexture(Skybox.NORTH, n);
        mySky.setTexture(Skybox.SOUTH, s);
        mySky.setTexture(Skybox.EAST, e);
        mySky.setTexture(Skybox.WEST, w);
        mySky.setTexture(Skybox.DOWN, d);
        mySky.setTexture(Skybox.UP, u);
        mySky.preloadTextures();
        mySky.lockBounds();
        mySky.lockMeshes();
    }
   
}

hmm try to create the SkyBox, before using it in buildworld()  :wink:



Then i think you are missing a camera setup, you can look at the flagrush tutorial to see whats all needed to create a BaseGame implementation.



Try to use the ResourceLocatorTool, because i think the double backslash only works on windows but i might be wrong.

Set up the Locator in your init method:


    protected void initGame()
    {
        try {
            ResourceLocatorTool.addResourceLocator(
                    ResourceLocatorTool.TYPE_TEXTURE,
                    new SimpleResourceLocator(GameClient.class.getResource("images/").toURI()));
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }



And later load the resources using the locator, without path.


n = (TextureManager.loadTexture(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "1.jpg"), Texture.MM_LINEAR, Texture.FM_LINEAR));


instead of

GameClient.class.getClassLoader().getResource("images\1.jpg")



Don't be afraid to debug and step through the code to see whats wrong.