[osg-users] DataVariance

0 views
Skip to first unread message

paul...@yahoo.com

unread,
Sep 17, 2008, 7:54:15 AM9/17/08
to osg-...@lists.openscenegraph.org
In OSG 2.6, is the DataVariance value only used by the Optimizer or is it also used during the frame processing? 

I've had some problems in the past with the StaticObjectDetectionVisitor and the Optimizer (assume "sharing" part of the Optimizer) doing some things to my scene graph which cause it to render incorrectly when I don't specify my DataVariance as being DYNAMIC.

Is there a reason why there is a StaticObjectDetectionVisitor being done when setSceneData() is performed independent of the Optimizer settings? Is the DataVariance value used by something other than the Optimizer?

Paul P.


_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Robert Osfield

unread,
Sep 17, 2008, 8:06:47 AM9/17/08
to OpenSceneGraph Users
Hi Paul,

In all the OSG 2.x series the DataVariance is used during the draw
traversal to monitor when all DYNAMIC StateSet and Drawables have been
dispatched, as once they have been the next frame can be started in a
parallel with the remaining STATIC objects are rendered (in
DrawThreadPerContex, CullThreadPerCameraDrawThreadPerContext threading
models.)

Robert.

Tomlinson, Gordon

unread,
Sep 17, 2008, 8:59:39 AM9/17/08
to OpenSceneGraph Users
The rule of thumb is that the Data Variance should be set to DYNAMIC on instances that change once that have been added to the Scenegraph. The short reason why is that this allows the Cull and draw threads to correctly handle and stage any changes that may be made in the app threads to the instances


Gordon

__________________________________________________________
Gordon Tomlinson

Product Manager 3D
Email : gtomlinson @ overwatch.textron.com


__________________________________________________________
(C): (+1) 571-265-2612
(W): (+1) 703-437-7651

"Self defence is not a function of learning tricks
but is a function of how quickly and intensely one
can arouse one's instinct for survival"
- Master Tambo Tetsura

paul...@yahoo.com

unread,
Sep 17, 2008, 10:52:39 AM9/17/08
to OpenSceneGraph Users
Thanks for the quick response...  
 
Then, any idea why my application is hanging when I attempt to render my first frame?? Below is the call stack of the two OSG threads.
 
The problem seems to exist when I include two different parts of my scene graph.  My scene graph consists of two Camera's at the root. Each renders to a different image array (using camera->attach(..., image);).
 
Each camera then has shared subgraphs attached which also contain a Camera node (for Ortho view for part of the scene) but with no attachments. 
 
The osgViewer's camera is unchanged (and I really don't need to "render" anything). 
 
Am I doing something wrong with these camera's?
 
While I'm at it, one more questions:
Is there  a way to turn on the OSG statistics overlay without using the keyboard. I've added the StatsHandler event handler. With osgProducer, I used to be able to do viewerEventHandler->setFrameStatsMode(mode).
 
Paul P.
 
THREAD #1
#0  0x4146627d in pthread_cond_wait@@GLIBC_2.3.2 ()
   from /lib/tls/libpthread.so.0
#1  0x41235a66 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/tls/libc.so.6
#2  0x40b1e364 in OpenThreads::Condition::wait (this=0x8281f88,
    mutex=0x8281f80)
    at /src/OpenSceneGraph_2.6/OpenSceneGraph-2.6.0/src/OpenThreads/pthreads/PThreadCondition.c++:137
#3  0x40ad9241 in OpenThreads::BlockCount::block (this=0x8281f80) at Block:133
#4  0x40ad7506 in osgViewer::ViewerBase::renderingTraversals (this=0x827ab58)
    at /src/OpenSceneGraph_2.6/OpenSceneGraph-2.6.0/src/osgViewer/ViewerBase.cpp:733
#5  0x40ad6a88 in osgViewer::ViewerBase::frame (this=0x827ab58,
    simulationTime=0)
    at /src/OpenSceneGraph_2.6/OpenSceneGraph-2.6.0/src/osgViewer/ViewerBase.cpp:592
#6  0x080858a7 in MyViewer::frame (this=0x827aad8, simTime=0)
    at MyViewer.hpp:131
 
THREAD #2
#0  0x4146627d in pthread_cond_wait@@GLIBC_2.3.2 ()
   from /lib/tls/libpthread.so.0
#1  0x41235a66 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/tls/libc.so.6
#2  0x40b1e364 in OpenThreads::Condition::wait (this=0x82786dc,
    mutex=0x82786d4)
    at /src/OpenSceneGraph_2.6/OpenSceneGraph-2.6.0/src/OpenThreads/pthreads/PThreadCondition.c++:137
#3  0x400aedf5 in OpenThreads::Block::block (this=0x82786d4) at Block:42
#4  0x40a8cdc7 in osgViewer::Renderer::TheadSafeQueue::takeFront (
    this=0x82786cc)
    at /src/OpenSceneGraph_2.6/OpenSceneGraph-2.6.0/src/osgViewer/Renderer.cpp:136
#5  0x40a8ee38 in osgViewer::Renderer::draw (this=0x8278640)
    at /src/OpenSceneGraph_2.6/OpenSceneGraph-2.6.0/src/osgViewer/Renderer.cpp:340
#6  0x40a9085e in osgViewer::Renderer::operator() (this=0x8278640,
    context=0x8272258)
    at /src/OpenSceneGraph_2.6/OpenSceneGraph-2.6.0/src/osgViewer/Renderer.cpp:640
#7  0x4086352d in osg::GraphicsContext::runOperations (this=0x8272258)
    at /src/OpenSceneGraph_2.6/OpenSceneGraph-2.6.0/src/osg/GraphicsContext.cpp:688
#8  0x4086c3ee in osg::RunOperations::operator() (this=0x829ea70,
-    context=0x8272258)
    at /src/OpenSceneGraph_2.6/OpenSceneGraph-2.6.0/src/osg/GraphicsThread.cpp:134
#9  0x4086bc7d in osg::GraphicsOperation::operator() (this=0x829ea70, object=Internal: global symbol `Object' found in RissAnimationPath.cpp psymtab but not in symtab.
Object may be an inlined function, or may be a template function
(if a template, try specifying an instantiation: Object<type>).
)
    at /src/OpenSceneGraph_2.6/OpenSceneGraph-2.6.0/src/osg/GraphicsThread.cpp:50
#10 0x408af928 in osg::OperationThread::run (this=0x829e810)
    at /src/OpenSceneGraph_2.6/OpenSceneGraph-2.6.0/src/osg/OperationThread.cpp:413
#11 0x4086bbf9 in osg::GraphicsThread::run (this=0x829e810)
    at /src/OpenSceneGraph_2.6/OpenSceneGraph-2.6.0/src/osg/GraphicsThread.cpp:38
#12 0x40b1d672 in OpenThreads::ThreadPrivateActions::StartThread (
    data=0x829e820)
    at /src/OpenSceneGraph_2.6/OpenSceneGraph-2.6.0/src/OpenThreads/pthreads/PThread.c++:170
#13 0x41463dec in start_thread () from /lib/tls/libpthread.so.0
#14 0x41228a2a in clone () from /lib/tls/libc.so.6


----- Original Message ----
From: Robert Osfield <robert....@gmail.com>
To: OpenSceneGraph Users <osg-...@lists.openscenegraph.org>
Sent: Wednesday, September 17, 2008 8:06:47 AM
Subject: Re: [osg-users] DataVariance

Hi Paul,

In all the OSG 2.x series the DataVariance is used during the draw
traversal to monitor when all DYNAMIC StateSet and Drawables have been
dispatched, as once they have been the next frame can be started in a
parallel with the remaining STATIC objects are rendered (in
DrawThreadPerContex, CullThreadPerCameraDrawThreadPerContext threading
models.)

Robert.

On Wed, Sep 17, 2008 at 12:54 PM,  <paul...@yahoo.com> wrote:

Robert Osfield

unread,
Sep 17, 2008, 11:03:33 AM9/17/08
to OpenSceneGraph Users
Hi Paul,

I can't say why your app might be hanging. Do the standard OSG
example hang on your machine?

Try running the view single threaded as something that might at least
flesh out whether threading is an issue at all.

Robert.

paul...@yahoo.com

unread,
Nov 20, 2008, 2:32:22 PM11/20/08
to OpenSceneGraph Users
When I change to SingleThreaded, I do not see the problem. The standard OSG examples work fine. Other cases of my problem also work fine.

Clearly, it's something in this app that is causing problems.  In the problem case, I'm rendering to two different image buffers and then reading the images out on the CPU. My scene is a "normal" scene except I have two cameras with each rendering to these different textures (i.e. a top and bottom view of the scene). I also have another camera rendering an orthogonal projection on top of the scene.

Paul P.

Robert Osfield

unread,
Nov 21, 2008, 4:10:20 AM11/21/08
to OpenSceneGraph Users
Hi Paul P.

You will have to debug this on your own I'm afraid, this type of issue
is not something one can resolve without seeing it first hand.

The best I can do is recommend that look into the using DataVariance
set to DYNAMIC on all StateSet and Drawable that you have in your
scene. This is the most likely cause of problems like this, but we've
already recommended this and you've made no comment whether you've
tried this. There have been lots written on this topic on osg-users
so please don't overlook the archives.

Robert.

Schmidt, Richard

unread,
Nov 21, 2008, 5:26:07 AM11/21/08
to OpenSceneGraph Users
Hi,
i have encountered some similiar problems with multithreading (and the
datavariance stuff).

One thing I have considered is changing the design of osg::Statesets and
osg::StateAttribute to immutable classes. So once the stuff is created
you can only change it by cloning it. At least for those objects you
don't have to think about datavariance anymore.

Attached you will find a 'setup' design pattern, which helps you
spawning immutable objects.

Richard
PS.: Just an idea.

TestClass.cpp
TestClass.h
Test.cpp

paul...@yahoo.com

unread,
Nov 24, 2008, 8:41:23 AM11/24/08
to OpenSceneGraph Users
I attempted to set all my nodes and state sets to DYNAMIC data variance by doing the following and it still is locking up on me (i.e. with the same call stack as below):

   SetDataVariance dataVariance;
   root->accept(dataVariance);

Where:

class SetDataVariance : public osg::NodeVisitor
{
public:
   SetDataVariance():   osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
 {};
   virtual void apply(osg::Node& node);
   virtual void apply(osg::Geode &node);
};
void SetDataVariance::apply(osg::Node& node)
{
   node.getOrCreateStateSet()->setDataVariance(osg::Object::DYNAMIC);
   traverse(node);
}
void SetDataVariance::apply(osg::Geode& geode)
{
    geode.getOrCreateStateSet()->setDataVariance(osg::Object::DYNAMIC);   
    geode.setDataVariance(osg::Object::DYNAMIC);
    for(unsigned int i=0;i<geode.getNumDrawables();++i)
    {
        osg::Drawable* drawable = geode.getDrawable(i);
        if (drawable)
        {
           drawable->getOrCreateStateSet()->setDataVariance(osg::Object::DYNAMIC);
           drawable->setDataVariance(osg::Object::DYNAMIC);
        }
    }
}

Removing a portion of my scene graph and the problem goes away (or is hidden)..  In particular, if I remove the node->addDrawable(geometry), the problem goes away. The problem exists even if node->addDrawable( new osg::Geometry).   In addition, turning off optimization doesn't seem to help. As I said before, using single threaded viewer and it works fine.
 
Any idea what is going on?

Robert Osfield

unread,
Nov 24, 2008, 8:45:47 AM11/24/08
to OpenSceneGraph Users
Hi Paul,

Could you try the CullDrawThreadPerContext thread model to see if that
works safely. If it does then the issue is almost certainly down to
some StateSet or Drawable in your scene graph that you are modifying
the contents that don't have the DataVariance set to DYNAMIC.

Robert.

paul...@yahoo.com

unread,
Nov 24, 2008, 10:57:00 AM11/24/08
to OpenSceneGraph Users
Using CullDrawThreadPerContext and it works..

If the problem is with stateset and Drawable not being set to DYNAMIC, why wouldn't my SetDataVariance NodeVisitor (see below) convert everything to DYNAMIC. I call this during my initialization of the scene graph.

Robert Osfield

unread,
Nov 24, 2008, 11:09:51 AM11/24/08
to OpenSceneGraph Users
Hi Paul,

On Mon, Nov 24, 2008 at 3:57 PM, <paul...@yahoo.com> wrote:
> Using CullDrawThreadPerContext and it works..
>
> If the problem is with stateset and Drawable not being set to DYNAMIC, why wouldn't my SetDataVariance NodeVisitor (see below) convert everything to DYNAMIC. I call this during my initialization of the scene graph.

Your visitor shouldn't use getOrCreateStateSet as this will be
creating a StateSet on all nodes and drawables. Use getStateSet and
an if statement to protect.

As to why it doesn't seem to fix the threading problem you have.
We'll I can't help you here. You have to debug your app, as I don't
have it in front of me, and I have plenty of work to do myself.

Robert.

Reply all
Reply to author
Forward
0 new messages