Trouble with Standardgame/Gamestate and Uncaught Exceptions

The last version of jme i worked with was 0.10

Since some week ago i started to adapt to 0.11 which introduced the TaskQueue and the new Standardgame along the LoadingGameState.

To get into the stuff i wrote some small piece of code and every now and then i get the following exception (crashing my testapp):

11.05.2007 12:59:37 com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
11.05.2007 12:59:37 com.jme.renderer.lwjgl.LWJGLRenderer <init>
INFO: LWJGLRenderer created. W:  640H: 480
11.05.2007 12:59:38 com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
11.05.2007 12:59:38 com.jmex.sound.openAL.SoundSystem <clinit>
INFO: DETECT OPERATING SYSTEM
11.05.2007 12:59:38 com.jmex.sound.openAL.SoundSystem <clinit>
INFO: CREATE OPENAL
11.05.2007 12:59:38 com.jmex.sound.openAL.SoundSystem initializeOpenAL
INFO: OpenAL initalized!
11.05.2007 12:59:38 com.jmex.sound.openAL.SoundSystem <clinit>
INFO: CREATE LISTENER
11.05.2007 12:59:38 com.jmex.game.state.GameStateManager create
INFO: Created GameStateManager
11.05.2007 12:59:38 com.jme.util.lwjgl.LWJGLTimer <init>
INFO: Timer resolution: 1000 ticks per second
11.05.2007 12:59:38 com.jme.scene.Node <init>
INFO: Node created.
11.05.2007 12:59:38 com.jme.scene.Node attachChild
INFO: Child (Some2DText) attached to this node (null)
11.05.2007 12:59:38 com.jme.scene.Node attachChild
INFO: Child (ProgressBar) attached to this node (null)
11.05.2007 12:59:38 com.jme.scene.Node attachChild
INFO: Child (Some2DText) attached to this node (null)
11.05.2007 12:59:38 com.jme.scene.Node <init>
INFO: Node created.
11.05.2007 12:59:38 com.jme.scene.Node <init>
INFO: Node created.
11.05.2007 12:59:38 com.jme.scene.Node attachChild
INFO: Child (Text) attached to this node (TextNode)
11.05.2007 12:59:38 com.jme.scene.Node <init>
INFO: Node created.
11.05.2007 12:59:38 com.jmex.terrain.util.MidPointHeightMap load
INFO: Created Heightmap using Mid Point
11.05.2007 12:59:38 com.jme.scene.Node attachChild
INFO: Child (Terrain) attached to this node (RootNode)
11.05.2007 12:59:38 com.jmex.game.DefaultUncaughtExceptionHandler uncaughtException
SCHWERWIEGEND: Main game loop broken by uncaught exception
java.lang.NullPointerException
at com.jme.renderer.lwjgl.LWJGLRenderer.draw(LWJGLRenderer.java:903)
at com.jme.scene.batch.TriangleBatch.draw(TriangleBatch.java:249)
at com.jme.renderer.RenderQueue.renderOrthoBucket(RenderQueue.java:301)
at com.jme.renderer.RenderQueue.renderBuckets(RenderQueue.java:240)
at com.jme.renderer.Renderer.renderQueue(Renderer.java:451)
at com.jme.renderer.lwjgl.LWJGLRenderer.displayBackBuffer(LWJGLRenderer.java:449)
at com.jmex.game.StandardGame.run(StandardGame.java:173)
at java.lang.Thread.run(Thread.java:619)
11.05.2007 12:59:38 com.jme.scene.Node attachChild
INFO: Child (player) attached to this node (RootNode)


I use a thinkpad T 41 with a Pentium M 1.5 Ghz system, 1 GB Ram, Windows XP, Java 1.6.0
Running the same on a dual core system with jdk 1.5_11 yields the same results. Every now and then i get the exception.

I suppose that i need to lock or unlock some queue while doing the stuff i do ?

Any help appreciated:

Here is the code. Its derived from TestStandardGame:
package org.kerim.client;

import com.jme.bounding.BoundingBox;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jmex.editors.swing.settings.GameSettingsPanel;
import com.jmex.game.StandardGame;
import com.jmex.game.state.GameStateManager;
import com.jmex.game.state.load.LoadingGameState;

public class Island {
  private MyDebugGameState state;
  private LoadingGameState lstate;
  private StandardGame game;

  public Island() throws Exception {
    // Instantiate StandardGame
    game = new StandardGame("Island");
    // Show settings screen
    GameSettingsPanel.prompt(game.getSettings());
    // Start StandardGame, it will block until it has initialized successfully,
    // then return
    game.start();
  }

  public void initGameStates() {
    // Create a DebugGameState - has all the built-in features that SimpleGame
    // provides
    // NOTE: for a distributable game implementation you'll want to use
    // something like
    // BasicGameState instead and provide control features yourself.
    lstate = new LoadingGameState();
    GameStateManager.getInstance().attachChild(lstate);
    //game.lock();
    lstate.setActive(true);
    lstate.setProgress(0.0f, "loading gamestate");
    state = new MyDebugGameState();
    GameStateManager.getInstance().attachChild(state);
    lstate.setProgress(0.3f, "loading objects");
    //game.unlock();
  }

  public void loadPlayer() {
    // Put our box in it
    Box box = new Box("player", new Vector3f(0, 0, 0), 1, 1.8f, 1);
    box.setModelBound(new BoundingBox());
    box.updateModelBound();
    // We had to add the following line because the render thread is already
    // running
    // Anytime we add content we need to updateRenderState or we get funky
    // effects
    box.updateRenderState();
    state.getRootNode().attachChild(box);
    lstate.setActive(false);
    state.setActive(true);
  }
 
  public void loadTerrain() {
   
//    TerrainBlock tb;
//    MidPointHeightMap heightMap = new MidPointHeightMap(128, 1.9f);
//    Vector3f terrainScale = new Vector3f(5,1,5);
//    tb = new TerrainBlock("Terrain", heightMap.getSize(), terrainScale,
//                                      heightMap.getHeightMap(),
//                                      new Vector3f(0, 0, 0), false);
//    //tb.setTrisPerPixel( 0.5f);
//    tb.setDistanceTolerance( 1.0f);
//    game.lock();
//    tb.setDetailTexture(1, 16);
//    tb.setModelBound(new BoundingBox());
//    tb.updateModelBound();
//    tb.setLocalTranslation(new Vector3f(0,0,0));
//    state.getRootNode().attachChild(tb);
//    lstate.setProgress(0.5f, "loaded terrain");
//    game.unlock();
   
   
  }
 
  public void setCS() {
    //state.getRootNode.setRenderState(cs);
  }

  public static void main(String[] args) throws Exception {
    Island i = new Island();
    i.initGameStates();
    i.loadTerrain();
    i.loadPlayer();

  }
}


As i know myself the problem surely is something "obvious" that i as usual simply am too blind to see alone.;)

Can you tell me what line 173 of StandardGame says (I'm at work and don't have access to the code at the moment).

It is :



display.getRenderer().displayBackBuffer();

Just for kicks try putting your instantiations of each GameState in GameTaskQueue and see if that makes a difference.



Something like:



WhateverGameState state = GameTaskQueue.getInstance().update(new Callable<WhateverGameState>() { public WhateverGameState call() throws Exception { return new WhateverGameState(); } }).get();



…but that was just pulled out of my head and is definitely a bit off of what you'd really write. :o

thanks darkfrog…

trying it with :

    Callable<?> loadState = new Callable() {
      public Object call() {
         
              lstate= new LoadingGameState();
         
          return lstate;
      }
  };
  GameTaskQueueManager.getManager().getQueue(GameTaskQueue.UPDATE).enqueue(loadState);

Will see if it works... i guess if i start and stop the app a day without trouble then it is "ok" ;)