[osg-users] DatabasePager - how to modify data during loading

Mike Connell michael.connell at gmail.com
Thu Jun 4 05:50:44 PDT 2015

Thanks Robert.

I hadn't actually considered the fact that the NodePath wouldn't be safe
outside the main thread. What I've now done is in a similar manner to the
terrain pointer - I added a "parent group" pointer to the Options object,
which is taken from the _group observer_ptr in the DatabaseRequest.

Then in our ReadFileCallback I can pass the parent group pointer off to the
main thread, which can lock it, safely extract the NodePaths and return the
results to the database pager thread. If the parent group has been removed
or detached from the scenegraph before we can obtain the lock that's no
problem - the loaded node isn't going to be inserted anyway.

In this way we keep the heavy processing (~800ms) in the background thread,
and only block the rendering thread for a minimal time - analysing the
NodePaths is of course fast, and the change to OSG is minimal.

best wishes

On Thu, 28 May 2015 at 10:43 Robert Osfield <robert.osfield at gmail.com>

> Hi Mike,
> The ReadFileCallback is an ideal place to modify the loaded scene
> graph as it's called from the database thread so won't impact the
> rendering performance.  The only problem is that you are wanting to
> know where the loaded subgraph will be attached to the scene graph.
> The only info available about this in the ReadFileCallback is the
> Terrain pointer that the DatabasePager passes into the read call via
> the Options object.  This Terrain pointer isn't the exact position the
> subgraph will be inserted, but for the purpose of osgTerrain it's
> sufficient for finding neighbouring tiles etc. to help with the
> tessellation process.
> Providing the NodePath for the insertion point from the DatabasePager
> to the Options object to read operation is something I looked at
> previous, but this wasn't thread safe as the NodePath itself can
> become invalidated by other threads - sometimes the DatabasePager has
> to deal with the node it intends to add the new subgraph to have been
> already deleted, so has to discard to the new subgraph.
> One option open to you could be to subclass from DatabasePager and
> override the updateSceneGraph(..) method.  Unfortunately this would be
> an operation done in the main thread so you'd need to be careful about
> the costs involved.
> Robert.
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20150604/31c9d2bf/attachment-0001.htm>

More information about the osg-users mailing list