Re-attaching nodes: IndexOutOfBoundsException

Hi all,



There seems to be some problem when detaching and re-attaching nodes/spatials in JME 3.0. I presume that it is a concurrency issue as the error only occurs sometimes.



i.e.

The following code will at times throw an IndexOutOfBoundsException:



myGeometry.removeFromparent();

…do stuff…

node.attachChild(myGeometry);



( My rational behind re-attaching spatials is that I would like to update meshes. )



Maybe somebody has any thoughts on this? Thanks.

Are you sure you only attach and detach while on the OpenGL thread?

[snippet id=“10”]

Nope. I didn’t realize that I had to do so. Could you elaborate?



Thanks Normen.

When the Spatials are part of the rootNode the OpenGL thread (“update loop”) is constantly working with them. So you have to do your logic on the nodes only when simpleUpdate()/update() is called or do it like in the code example above. Its a general way of doing multithreading in Java, read about “Java Concurrency” to find out more. The code in the run() method of the callable is executed later on the OpenGL thread, basically just before the simpleUpdate() method is called in the run loop. If you want to wait for a result, you can do so via the “Future” object thats returned by the enqueue method.

1 Like

Thanks. You’re very helpful, as aways.