rootNode.attachChild in onAnalog

Hi Guys…

My game is occasionally crashing with the exception

java.lang.ArrayIndexOutOfBoundsException: 2
    at com.jme3.util.SafeArrayList.get(SafeArrayList.java:258) 
    at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:683)

which i understand is because i have been changing the scene graph out-side the main update loop… (im in process of fixing these)

But according to to the wiki i can only make changes in

“only in Control.update(), AppState.update(), or SimpleApplication.simpleUpdate()”

So what about onAnalog and onAction?

public class RealTimeStrategyAppState extends AbstractAppState implements ActionListener, AnalogListener{

    public void onAnalog(String name, float value, float tpf) {
        app.getRootNode().detachChild(line1);
    }

    public void onAction(String name, boolean isPressed, float tpf) {
        app.getRootNode().detachChild(line1);
    }

}

Is it ok for me to change the scene graph here?
Or is this bad as well?

Yes, it’s ok. All Input stuff is processed on the update thread as well.

1 Like

Technically if you dont start a Thread nearly anything is on the MainThread.

If you have multithreading make use of App.enqueue