Discussion:
[osg-users] Switch call to viewer::frame() between threads
Steven Powers
2018-09-11 06:48:15 UTC
Permalink
I am attempting to switch which thread I call viewer::frame in.

I realize my viewer in thread A, call viewer::frame() several times, do some loading, then switch the call to viewer::frame() to thread B. When I do so the items within the window still update but I am unable to move/resize/select the window.

It seems to be dependent on which thread I call viewer::realize from. If I call it from thread B then the opposite is true. Or perhaps it is dependent on what thread I call createGraphicsContext on???

What is the elegant or appropriate way to accomplish such a feat. Is the realize operation thread specific or is it the keyboard handlers?

Thanks in advance for any advice/ help that can be provided.

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74699#74699
Robert Osfield
2018-09-11 15:42:51 UTC
Permalink
Hi Steven,

I haven't heard of anyone trying to call frame from multiple threads
before, and personally wouldn't recommend doing it. I have said why
you are wanting to do this so can't judge how sensible or daft it is.

If you want an application that has multiple threads that modifying
something and then want the scene graph to be rendered to show it then
I'd suggest that you have a viewer frame loop with frame barrier that
the various thread share and release when they want the frame to
render, then have a dedicated thread (possibly the main application
thread for simplicity) that then sits of this barrier waiting to be
released.

You'd still need to be really careful about modifying data in a thread safe way.

Robert.
Ravi Mathur
2018-09-11 16:02:22 UTC
Permalink
Hi Steven,

What OS are you on? On OSX, event handling MUST happen from the main
thread, so you have to coordinate the frame loop between threads.

Ravi
Post by Robert Osfield
Hi Steven,
I haven't heard of anyone trying to call frame from multiple threads
before, and personally wouldn't recommend doing it. I have said why
you are wanting to do this so can't judge how sensible or daft it is.
If you want an application that has multiple threads that modifying
something and then want the scene graph to be rendered to show it then
I'd suggest that you have a viewer frame loop with frame barrier that
the various thread share and release when they want the frame to
render, then have a dedicated thread (possibly the main application
thread for simplicity) that then sits of this barrier waiting to be
released.
You'd still need to be really careful about modifying data in a thread safe way.
Robert.
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Steven Powers
2018-09-11 17:41:43 UTC
Permalink
Thanks for the replies. This is mostly experimental and I have already been calling frame() from a child thread for a while now without any problems as long as I call createGraphicsContext() and realize() from the same child thread.

This effort is to streamline the initialization of the application on the mainthread which would require me to call realize/cGC() on a different thread.

This seems to break all of the windows event control when I start calling frame() on a thread other than the one that created the graphics context and called realize().

My question is if I can re-initialize this or do I have to create a fresh window to get this to work.

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74710#74710
Robert Osfield
2018-09-11 18:23:19 UTC
Permalink
Hi Steven,

osgViewer was never designed to be used in the way you want to use it,
there are almost certainly better ways of doing what you want to do
functionally and a simpler way that trying play games with who invokes
frame. It's just a bad approach so trying to help do something that
isn't sensible is a waste of our time and yours.

Robert.
Post by Steven Powers
Thanks for the replies. This is mostly experimental and I have already been calling frame() from a child thread for a while now without any problems as long as I call createGraphicsContext() and realize() from the same child thread.
This effort is to streamline the initialization of the application on the mainthread which would require me to call realize/cGC() on a different thread.
This seems to break all of the windows event control when I start calling frame() on a thread other than the one that created the graphics context and called realize().
My question is if I can re-initialize this or do I have to create a fresh window to get this to work.
------------------
http://forum.openscenegraph.org/viewtopic.php?p=74710#74710
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Loading...