Crashes if modify node during update?

Hi Everyone,

I’ve a got a number of 3D vehicles on a flat terrain, and they have their position values updated via XMPP messages, received on a separate thread. When that thread receives a new position, it calls a public method from my main class, which then applies vehicleNode.setLocalTranslation(…). At first, I was getting crashes due to the scene being changed while an update was occuring, which didn’t surprise me too much, I think I hit a similar problem in openscenegraph a few years back.

So, I added a call too rootNode.updateGeometricState(), but I see a message saying this isn’t really needed.

It seems a bit more stable with this call, but I still get occasional crashes. Struggling to reproduce one now so I can’t get the exact error message, but I think its pretty standard.

So, my question is, can I get away with this approach with a bit of tweaking? Or am I going to need to extend the main class with an update loop, which could check a message queue of position updates, update the vehicle position and then allow the render? Or some better approach?



No, you cannot get away with it that way.

If you’re playing with spatials in a different thread, use Future and enqueue what you want to do. This should solve your problem.

updateGeometricState() should only be used if you’re managing the “rootnode” by yourself. But that’s a different subject altogether.

Application.enqueue(Callable) as answerd in numerous treads

Just to follow up on what the others are saying. You cannot modify the scene graph from another thread. It’s super-bad dangerous. All updates to the attached scene graph must be done on the rendering thread. (Using the methods the others have suggested and that are documented on the wiki.)

The error you get is a check attempting to save you from yourself. All you do by calling updateGeometricState manually is suppress the error… but you are still doing bad things. It’s like if a fire alarm is going off so you cut the wires to the alarm instead of putting out the fire.

1 Like

Thanks guys!

In the end, I found handling it via the simpleUpdate method alot easier; so my XMPP thread can update a vehicles position info, but the spatial is only touched during simpleUpdate + I can do dead reckoning there easily enough too.