Quantcast

remove MapNode

classic Classic list List threaded Threaded
5 messages Options
Dmitry Kuz Dmitry Kuz
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

remove MapNode

Hi all.
I have simple code:

#include <osgViewer/Viewer>
#include <osgGA/TrackballManipulator>
#include <osgEarth/MapNode>
#include <osgEarth/Registry>

int main(int argc, char *argv[])
{
    osgViewer::Viewer *m_viewer = new osgViewer::Viewer();
    m_viewer->setUpViewInWindow(50,50,1000,800);

    osg::ref_ptr<osg::Group> m_root = new osg::Group();
    osg::ref_ptr<osgEarth::Map> m_map = new osgEarth::Map;
    osg::ref_ptr<osgEarth::MapNode> m_mapNode = new osgEarth::MapNode(m_map);

    m_root->addChild(m_mapNode);

    m_viewer->setSceneData(m_root);
    m_viewer->setCameraManipulator(new osgGA::TrackballManipulator());

    for(int i = 0; i < 60; ++i){
        m_viewer->frame();
    }

    delete m_viewer;
    osgEarth::Registry::instance(true);
    //doSomething()

    return 0;
}

It crashed in destroy SpatialReference.
If to comment out osgEarth::Registry::instance(true), MapNode not removed until completion of the program.

Tell me, what am I doing wrong?


gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: remove MapNode

Dmitry,

MapNode is held with an osg::ref_ptr, and so it will not be destructed until the ref_ptr goes out of scope. Hope this helps.
Glenn Waldron / Pelican Mapping
Dmitry Kuz Dmitry Kuz
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: remove MapNode

gwaldron,
Thank you. My example was incorrect.

osg::Group *m_root = new osg::Group();
osgEarth::Map *m_map = new osgEarth::Map;
osgEarth::MapNode *m_mapNode = new osgEarth::MapNode(m_map);

m_root will be removed when m_viewer destructed. But m_map and m_mapNode not removed.

What should I do to all objects osgEarth were removed by the time of the call to doSomething?

I hope my problem will be clearer after that.

gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: remove MapNode

Dmitry,
Thanks. We recently did some updates that will ensure that all Map objects get properly destructed when the scene graph is destructed. These changes are in the master branch of osgEarth, and we are going to apply them to the 2.8 branch as well in the near future. Please try the master and see if it resolves your issue.
Glenn Waldron / Pelican Mapping
Dmitry Kuz Dmitry Kuz
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: remove MapNode

This post was updated on .
I try to solve this problem again... I have updated master and I have tested on an example:

LoadLybrary("mylibrary")
...
//mylibrary
    osgViewer::Viewer *m_viewer = new osgViewer::Viewer();
    m_viewer->setUpViewInWindow(50,50,1000,800);
    m_viewer->setSceneData(new osgEarth::MapNode(new osgEarth::Map));
    m_viewer->run();
...

    delete m_viewer;
    //osgEarth::Registry::instance(true);

//mylibrary

FreeLibrary()

osg and osgearth dlls aren't unloaded.
What will you advise?


Loading...