Headless game crashes sometimes

When I make a headless game and start it, 9 out of 10 times it runs great however sometimes when I run the game I get the following error message on start-up



Feb 3, 2008 7:13:59 PM com.jme.scene.Node attachChild

INFO: Child (testObject) attached to this node (Basic state: RootNode)

Feb 3, 2008 7:13:59 PM com.jme.scene.Node attachChild

INFO: Child (testObject2) attached to this node (Basic state: RootNode)

Feb 3, 2008 7:13:59 PM com.jme.scene.Node detachChildAt

INFO: Child removed.

Feb 3, 2008 7:13:59 PM com.jmex.game.DefaultUncaughtExceptionHandler uncaughtException

SEVERE: Main game loop broken by uncaught exception

java.lang.IndexOutOfBoundsException: Index: 3, Size: 3

        at java.util.ArrayList.RangeCheck(ArrayList.java:547)

        at java.util.ArrayList.get(ArrayList.java:322)

        at com.jme.scene.Node.updateWorldBound(Unknown Source)

        at com.jme.scene.Spatial.updateGeometricState(Unknown Source)

        at com.jmex.game.state.BasicGameState.update(Unknown Source)

        at com.jmex.game.state.GameStateNode.update(Unknown Source)

        at com.jmex.game.StandardGame.update(Unknown Source)

        at com.jmex.game.StandardGame.run(Unknown Source)

        at java.lang.Thread.run(Thread.java:619)

Feb 3, 2008 7:13:59 PM com.jme.scene.Node attachChild

INFO: Child (testObject2) attached to this node (dynamicNode)

Feb 3, 2008 7:13:59 PM com.jme.scene.Node attachChild

INFO: Child (null) attached to this node (dynamicNode)



I know this is a pretty vague description. What could I do to clarify it? When I restart the headless game it runs fine again.

Perhaps you are using multiple threads, and you are not detaching children in the GL Thread?

Headless implies that there is no GL thread, but there might still be some kind of main thread. I agree in that it's most likely a threading issue.

In my headless test app I create 2 Gamestates , so that could explain the thread issue perhaps? Since, as far as I know, gamestates are threads.





Is there a different way gamestates should be handled in a headless game? Right now I declare the gamestate, attach it to the GameStateManager and activate the state.

Darklord said:

In my headless test app I create 2 Gamestates , so that could explain the thread issue perhaps? Since, as far as I know, gamestates are threads.


Is there a different way gamestates should be handled in a headless game? Right now I declare the gamestate, attach it to the GameStateManager and activate the state.



i dont recall game states being seperate threads from the main game loop thread. i mean they just manage their own scene graphs and thats about it.

well, if u r using standard game, i dont know if headless game extends standard game or not, but if they do, u should use task queue manager to handle ur states.

When you add the GameStates to the Manager, what happens is that at each update (in the GL or Dummy thread) the update method of the GameState is called. They are not its own thread, they are just called from the main render one.



The problem seems to be coming from a State trying to access a child that has been detached (most likely) by another thread, like a GUI, or an Input handler.

Thanks alot guys, with this info I now atleast know in which direction I should be looking and have a hunch where the problem lies.



Thanks again!