Hello All,

      Now I'm doing the work of wrapping OSGEarth into ActiveX control which
is to be placed inside a web page. I use the framework of FireBreath to
implement this task. But I encounter some strange problems as follows:

Development Environment: Visual Studio 2012, Windows 8.1, IE 11, OSG 3.2.0,
OSGEarth 2.5

1.     I created an new FireBreath project to wrap OSGEarth into ActiveX
control, compiled with Release mode. When I open the web page with this
ActiveX control, the earth can be displayed normally. when the model data (
larger than 100 M ) is loaded progressively, the web browser will crash. I
tied to load a small model ( about 5M ), the browser will not crash.  Then I
tried to use osgearth_viewer to load the data, it will not crash too. It
seems that the browser can't hold too much memory. Any solution?

Main source code is as follows,

 

bool OsgWeb::onWindowAttached(FB::AttachedEvent* evt, FB::PluginWindow* win)

{

    FB::PluginWindowWin* window =
reinterpret_cast<FB::PluginWindowWin*>(win);

    if ( window )

    {

       osgViewer::GraphicsWindowWin32::WindowData* windata = new
osgViewer::GraphicsWindowWin32::WindowData(

           window->getHWND() );

       // This works under Windows only

       osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
osg::GraphicsContext::Traits;

       traits->x = 0;

       traits->y = 0;

       traits->width = window->getWindowWidth();

       traits->height = window->getWindowHeight();

       traits->windowDecoration = false;

       traits->doubleBuffer = true;

       traits->sharedContext = 0;

       traits->setInheritedWindowPixelFormat = true;

 

       traits->inheritedWindowData = windata;

 

       osg::ref_ptr<osg::GraphicsContext> gc =
osg::GraphicsContext::createGraphicsContext( traits.get() );

       osg::ref_ptr<osg::Camera> camera = new osg::Camera;

       camera->setGraphicsContext( gc );

       camera->setViewport( new osg::Viewport(0, 0, traits->width,
traits->height) );

       camera->setClearMask( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );

       camera->setClearColor( osg::Vec4f(0.2f, 0.2f, 0.6f, 1.0f) );

       camera->setProjectionMatrixAsPerspective(30.0f,
(double)traits->width/(double)traits->height, 1.0, 1000.0 );

 

       _viewer.setCamera( camera.get() );

       

       _viewer.setKeyEventSetsDone( 0 );

 

       //Tell the database pager to not modify the unref settings

       _viewer.getDatabasePager()->setUnrefImageDataAfterApplyPolicy( false,
false );

 

       // install our default manipulator (do this before calling load)

       _viewer.setCameraManipulator( new osgEarth::Util::EarthManipulator()
);

 

       // load an earth file, and support all or our example command-line
options

       // and earth file <external> tags

       int argc = 1;

       char *argv[] =
{"E:\\Software\\OSG\\OSGEarth\\tests\\vertical_datum.earth"};

       osg::ArgumentParser arguments(&argc,argv);

       osg::Node* node = osgEarth::Util::MapNodeHelper().load( arguments,
&_viewer );

       if ( node )

       {

           _viewer.setSceneData( node );

 

           // configure the near/far so we don't clip things that are up
close

           _viewer.getCamera()->setNearFarRatio(0.00002);

           _viewer.getCamera()->setSmallFeatureCullingPixelSize(-1.0f);

 

           //_viewer.run();

       }

       _thread = new RenderingThread;

       _thread->viewerPtr = &_viewer;

       _thread->start();

    }

    return false;

}

 

class RenderingThread : public OpenThreads::Thread

{

public:

    RenderingThread() : OpenThreads::Thread(), viewerPtr(NULL) {}

    

    virtual ~RenderingThread();

    

    virtual void run();

    

    osgViewer::Viewer* viewerPtr;

};

 

RenderingThread::~RenderingThread()

{

    if ( viewerPtr ) viewerPtr->setDone( true );

    while( isRunning() )

    OpenThreads::Thread::YieldCurrentThread();

}

 

void RenderingThread::run()

{

    if ( !viewerPtr ) return;

    do

    {

       viewerPtr->frame();

    }

    while ( !testCancel() && !viewerPtr->done() );

    viewerPtr = NULL;

}

 

2.     When I debug the sourcecode, the error occurs on the statement.
traits->inheritedWindowData = windata; 

Obviously this statement has nothing to do with loading model data. Why it
has different problem between release mode and debug mode?

 

Every Guru, Please help me to solve these two problem.

 

Thanks you all in advance!

 

Best regards

 

Glen

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

Reply via email to