Robert,

Here's a simple viewer I wrote that does non-continuous render and exhibits
the problem.  You can just run it like the osgviewer application, passing in
the path to a database on the command line.  I have also included a stats
handler that will cause the app to switch to continuous render while it is
onscreen.  I have only tested this with osgEarth, so I don't know if the
problem manifests itself with VPB databases.  The reloading problem wouldn't
manifest itself when I ran an animation path because playing back the
animation essentially caused continuous rendering, but if you load an earth
database and move around a bit in the scene you should see the behavior.  I
can get it to happen pretty reliably when I load the yahoo satellite images
using osgEarth, then quickly zoom in on an area that I have cached.  When I
stop zooming and zoom back out or pan around, the tiles start reloading.  I
had a co-worker try this out and he was able to duplicate the problem pretty
quickly, so hopefully it will happen easily for you too.

Evan


On Thu, Apr 23, 2009 at 2:14 AM, Robert Osfield <robert.osfi...@gmail.com>wrote:

> Hi Evan,
>
> On Wed, Apr 22, 2009 at 10:05 PM, Evan Andersen <andersen.e...@gmail.com>
> wrote:
> > Ryan,
> >
> > Thank you for the suggestion.  When I call
> > setTargetMaximumNumberOfPagedLOD(0) on the database pager, as you
> suggested
> > and then set the expiry delay to DBL_MAX and the expiry frames to 10, as
> > Jason Suggested the problem seems to go away.  I'm not really sure why
> this
> > works.  It seems like the default behavior should work in my usage case,
> but
> > at least it is working now.
>
> Could you modify one of the OSG examples to reproduce your application
> usage style and use this to recreate the problem.  I could then have a
> look at why the new (and now default) expiry scheme is not working
> correctly.  As you say it should work, at present I don't know why the
> old scheme is able to work.
>
> Robert.
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
#include <osgViewer/viewer>
#include <osgDB/ReadFile>
#include <osgViewer/ViewerEventHandlers>

#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/StateSetManipulator>
#include <osgGA/TerrainManipulator>

#include <OpenThreads/Thread>
#include <cfloat>

// The stats handler has to be modified to request continuous updates
// when stats are being displayed
class MyStats : public osgViewer::StatsHandler
{
protected:
    ~MyStats() {}
    int keyPresses;
public:
    MyStats() : osgViewer::StatsHandler(), keyPresses(0) {}
    virtual bool handle(const osgGA::GUIEventAdapter &ea, 
osgGA::GUIActionAdapter &aa)
    {
        if( ea.getEventType() != osgGA::GUIEventAdapter::KEYDOWN )
            return false;

        int key = ea.getKey();

        if(key == -1)
            return false;

        if(key == 's') {
            if(keyPresses < 4)
            {
                aa.requestContinuousUpdate(true);
                keyPresses++;
            }
            else
            {
                keyPresses = 0;
                aa.requestContinuousUpdate(false);
                aa.requestRedraw();
            }

            return osgViewer::StatsHandler::handle(ea, aa);
        }
        return false;
    }
};

class MyViewer : public osgViewer::Viewer
{
public:
    MyViewer() : osgViewer::Viewer(), needsRender(true), 
continuousUpdate(false) {}
    MyViewer(osg::ArgumentParser &arguments) : osgViewer::Viewer(arguments), 
needsRender(true), continuousUpdate(false) {}

    virtual void requestRedraw()
    {
        needsRender = true;
    }

    virtual void requestContinuousUpdate(bool needed=true)
    {
        continuousUpdate = needed;
    }

    virtual int run()
    {
        // From osgViewer::Viewer
        if (!getCameraManipulator() && getCamera()->getAllowEventFocus())
        {
            setCameraManipulator(new osgGA::TrackballManipulator);
        }

        setReleaseContextAtEndOfFrameHint(false);

        // From osgViewer::ViewerBase
        if (!isRealized())
        {
            realize();
        }

        /*******************************************************/
        // This block of code seems to fix the reloading problems
        //getDatabasePager()->setTargetMaximumNumberOfPageLOD(0);
        //getDatabasePager()->setExpiryDelay(DBL_MAX);
        //getDatabasePager()->setExpiryFrames(10);
        /******************************************************/

        while (!done())
        {
            frame();

            // Sleep for 10 miliseconds.  This is just an arbitrary value, but 
we'd
            // do something intelligent to make the loop run at a desired rate.
            OpenThreads::Thread::microSleep(10000);
        }

        return 0;
    }

    virtual void frame(double simulationTime=USE_REFERENCE_TIME)
    {
        if (_done) return;

        if (_firstFrame)
        {
            viewerInit();

            if (!isRealized())
            {
                realize();
            }

            _firstFrame = false;
        }

        advance(simulationTime);

        eventTraversal();

        // If the database pager is going to update the scene the render flag is
        // set so that the updates show up
        if(getDatabasePager()->requiresUpdateSceneGraph())
            needsRender = true;

        updateTraversal();

        if(needsRender || continuousUpdate)
        {
            renderingTraversals();
            needsRender = false;
        }
    }

protected:
    ~MyViewer() {}
    bool needsRender;
    bool continuousUpdate;
};


int main(int argc, char* argv[])
{
    osg::ArgumentParser arguments(&argc,argv);

    osg::ref_ptr<MyViewer> viewer = new MyViewer(arguments);

    // set up the camera manipulators.
    {
        osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = 
new osgGA::KeySwitchMatrixManipulator;

        keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new 
osgGA::TrackballManipulator() );
        keyswitchManipulator->addMatrixManipulator( '2', "Flight", new 
osgGA::FlightManipulator() );
        keyswitchManipulator->addMatrixManipulator( '3', "Drive", new 
osgGA::DriveManipulator() );
        keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new 
osgGA::TerrainManipulator() );

        viewer->setCameraManipulator( keyswitchManipulator.get() );
    }

    viewer->addEventHandler(new MyStats());

    osg::ref_ptr<osg::Node> node = osgDB::readNodeFiles(arguments);

    if(node.valid())
    {
        viewer->setSceneData(node);
        viewer->run();
    }

    return 0;
}

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

Reply via email to