should care be taken adding Nodes to scenegraph?

Hi,

I know xith is not thread-safe, but sometimes it seems I can get away without strictly syncronizing some stuff.

My question concerns this scenario:

If a MenuItem fires a method which creates a Cube and add it to the current scene, is this safe? It seems that the objet could be added while the scene is being rendered and this could(?) potentialy mess up things. Is it good to be paranoid about it or nothing disruptive can actully happen?

I thought a solution would be to add an event queue mechanism, so that only from the rendering loop, the Cube is added. I already do this to handle MouseEvents, but sometimes things are not smooth and I would really like to adopt a good approach to deal with these issues.

cheers :stuck_out_tongue:
Pedro

You anyway have AWT Event Queue. What you can do is to synchronize against your View instance:

View.renderOnce() is declared as synchronized, so if you will place your scenegraph modification in

synchronized (view) {
// modify SG here
}

and can be sure that it will not happen during the rendering.

This way has its pros and cons, for example, if you will load textures or parse big models, you may see pauses in rendering, so you may want to load everything before “synchronized (view)…” and then just attach ready objects to scenegraph.

Yuri

Thanks Yuri.

But I face another problem, because some of the events call methods that require picking and I cannot do anything to avoid getting an exception (since I don’t think there is a way to trick jogl and change the currentThread).

So it seems that events must be handled from the rendering thread.

As I’ve seen in the Camera class posted in the forum, you can have a flag to signalise that an event occured and needs to be handled.

BUT, if there is more than one event per 1/FPS, it seems to me that you would lose some events. That’s why I was considering having an event queue, so that at each rendering loop, events in the queue get handled (but I might lose perfomance)

I am new to 3d/game programming, so I’m not sure how this is treated. Do we just establish that certain events won’t be caught and we ignored them intentionally?

Sory if it’s a silly question to ask :stuck_out_tongue:

Yes, if you want to use picking, you are limited to calling picking functions from rendering loop. And if you want to handle more than 1 event per frame rendered, you sould use a kind of event queue. This seems to be an easiest way, but there are also another possibilities.

Yuri