[osg-users] OsgViewer and Windows Forms
Todd J. Furlong
todd at inv3rsion.com
Tue Nov 10 07:11:10 PST 2009
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
Comments or suggestions?
More information about the osg-users