HelloIntersection potential bug when removing from node detachChild() method

I'm getting an error with the HelloIntersection code, in jmetest.TutorialGuide. The problem I think is stemming from the Node detachChild method.



The problem occurs when the TriMesh bullet is removed from the rootNode in the Controller's update method.




   class BulletMover extends Controller {
   

Altering the structure of the scenegraph in the updateGeometricState methods or in the controller update is not the best idea. Though it makes things easier if it is at least possible.

Rather than checking getQuantity each time, I would suggest to catch the ArrayOutOfBoundsException instead (right around that get(i) statement), as it's a seldom case and traversing the scenegraph has to be fast in the common case.

Still removing it, and then using the suggested fix, would mean the bullet after the current bullet (which is removed) would be skipped, so that's not perfect either.



But we should definatly fix it another way. Maybe set it to null, and then remove it later.

I agree the maxQuanity() optimization should stay. I'm not sure but I think this optimization was recently added (I can't check the CVS where I'm at right now).



Irrisor, how else would you suggest removing that bullet object from the scene graph if not in the controller's update method? I was thinking you could mark that object for removal and then in the simpleUpdate() method you could remove any queued up nodes.



public class HelloIntersection extends SimpleGame {
//...STUFF OMITTED
   class BulletMover extends Controller {
   

dougnukem, the way you suggest is a good way, I'll probably put it in CVS/Wiki soon.



I guess the question is, should jME have something like that build in, but I don't really think it's needed. Maybe some people think differently though?