Avoiding conflicting modifications
We have discussed OSG's multithread implementation and thread safety in a very simple and easy way. The theory of the processing architecture is really out of the scope of this book. But in order to show the importance of maintaining data variance of scene objects, we need to briefly talk about the threading model.
OSG can make the draw traversal, which transfers data to the OpenGL pipeline run in a separated thread. It must be synchronized with other draw traversals in every frame, but part of the draw traversal can usually overlap the update traversal coming from the next frame, which improves the rendering efficiency and reduces frame latency. That means that the frame()
method of osgViewer::Viewer
will return while the drawing work is still active. Data changes in update callbacks could then conflict with the unfinished rendering process and cause unexpected behaviors, and even crashes.
OSG supplies a solution in the setDataVariance()
method, which...