removeFromParent() causes exception


Im removing some nodes from the rootNode. Im not using the simpleUpdate() method (i extend SimpleGame at the moment) which may be the reason. I start the  thread that does some stuff and at the end it calls the method from one of my classes that removes a node it contains from the rootNode and most often i get this:

SEVERE: Exception in game loop
java.lang.IndexOutOfBoundsException: Index: 52, Size: 52
   at java.util.ArrayList.RangeCheck(Unknown Source)
   at java.util.ArrayList.get(Unknown Source)
   at com.jme.scene.Node.draw(Unknown Source)
   at com.jme.scene.Spatial.onDraw(Unknown Source)
   at com.jme.renderer.lwjgl.LWJGLRenderer.draw(Unknown Source)
   at Source)
   at Source)
   at MojaKlasa.main(

Any ideas?

The scenegraph API is not threadsafe (for perfomance reasons). Make sure you only access it from the main thread or synchronize your access to it.

Thanks i suspected that this might be the case. Problem solved.