Hi Todd,
 
I've had the same choices to make for my .NET / OSG program. I'm not sure 
whether or not the .NET timer / Invalidate is a stable approach, FYI I'll just 
explain the solution I've chosen.
To avoid all the mutexes and threading issues, I went for a very simple 
solution. A render thread loops to call frame() and a UI thread processes user 
actions. Changes to the scene graph are made in two steps:
 
* The UI thread sets a flag indicating what kind of change to the scenegraph is 
required;
* Each iteration, the render threads checks (and clears) all flags and makes 
the required scenegraph changes before calling frame().
 
Of course, depending on your application, this can be kind of awkward (although 
you can replace flags with more detailed "modification objects" containing 
loaded models etc.).
 
Kind regards,

Ruben

________________________________

From: [email protected] on behalf of Todd J. Furlong
Sent: Tue 11/10/2009 4:11 PM
To: OpenSceneGraph Users
Subject: [osg-users] OsgViewer and Windows Forms



I have a .NET Windows Forms application with 2 OSG-based classes:
1. A UserControl/OsgViewer based class, and
2. An OSG-based "engine" that handles file loading, scenegraph mods, etc.

The .NET example from the OSG website gets the viewer initialized:
http://www.openscenegraph.org/projects/osg/wiki/Support/FAQ#HowdoIembedanOSGviewerina.NETcontrol

My question is: What is the best way to call the viewer frame function
in this application?

I have tried updating the viewer in a new thread.  It appears to perform
well, but it presents thread safety problems because my scenegraph
modifications (from the "engine") mostly take place in the UI thread
(button press events, etc).  I can simplify the engine code (avoid
mutexes around function calls) if I can get the viewer to update on that
thread.

To move the viewer onto the UI thread, I am calling the viewer frame
function in an override of the OnPaint method of the UserControl class.
  I've created a Forms timer that periodically calls Invalidate on the
UserControl to make sure OnPaint  is called with some regularity.  Other
timer-related code insures that the Invalidate call isn't made at a
greater frequency than we expect the viewer to be able to render.  It
appears to be working OK, but I'm worried that this approach will be
fragile as we run this application on different systems with different
scene contents.

Comments or suggestions?

Thanks,
Todd
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org 
<https://tnoportal.tno.nl/listinfo.cgi/,DanaInfo=lists.openscenegraph.org+osg-users-openscenegraph.org>
 


This e-mail and its contents are subject to the DISCLAIMER at 
http://www.tno.nl/disclaimer/email.html

<<winmail.dat>>

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to