[osg-users] OsgViewer and Windows Forms

Smelik, R.M. (Ruben) ruben.smelik at tno.nl
Tue Nov 10 07:48:59 PST 2009

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,



From: osg-users-bounces at lists.openscenegraph.org 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:

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

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?

osg-users mailing list
osg-users at lists.openscenegraph.org
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 6020 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20091110/7d5d1dc8/attachment.bin>

More information about the osg-users mailing list