issue with removing gdal elevation layer

classic Classic list List threaded Threaded
8 messages Options
benedikt.schwarz benedikt.schwarz
Reply | Threaded
Open this post in threaded view
|

issue with removing gdal elevation layer

Dear all,

I want to add and remove different layers on runtime with osgearth 3.1. For this I am currently using map->AddLayer and RemoveLayer. For XYZImage layers this seems to work fine, but sometimes I get a memory access error when removing a gdal elevation layer. Am I using the API in a wrong way?

Best,
Benedikt

----------------------------

Some more details on the memory error.
RemoveLayer calls the close() of the layer and by that GDALElevationLayer::closeImplementation(), which sets the profile to NULL.

Then the memory access error which sometimes happens is in ElevationLayer::createHeightFieldInKeyProfile(const TileKey& key, ProgressCallback* progress) line 492.
if (hf.valid() && !key.getExtent().getSRS()->isVertEquivalentTo(getProfile()->getSRS()))
because getProfile()->getSRS() calls a member function on a nullpointer.

Benedikt
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: issue with removing gdal elevation layer

Benedikt,
Can you provide a stack trace?
Glenn Waldron / Pelican Mapping
benedikt.schwarz benedikt.schwarz
Reply | Threaded
Open this post in threaded view
|

Re: issue with removing gdal elevation layer

Dear Glen,

thank you for your help, here is the call stack.

Best, Benedikt

osgEarth.dll!OGRFeature::GetStyleTable() Zeile 1820 C++
osgEarth.dll!osgEarth::ElevationLayer::createHeightFieldInKeyProfile(const osgEarth::TileKey & key, osgEarth::ProgressCallback * progress) Zeile 492 C++
osgEarth.dll!osgEarth::ElevationLayer::createHeightField(const osgEarth::TileKey & key, osgEarth::ProgressCallback * progress) Zeile 364 C++
osgEarth.dll!osgEarth::ElevationLayerVector::populateHeightField(osg::HeightField * hf, float * resolutions, const osgEarth::TileKey & key, const osgEarth::Profile * haeProfile, osgEarth::RasterInterpolation interpolation, osgEarth::ProgressCallback * progress) Zeile 810 C++
osgEarth.dll!osgEarth::ElevationPool::getOrCreateRaster(const osgEarth::Internal::RevElevationKey & key, const osgEarth::Map * map, bool acceptLowerRes, osgEarth::ElevationPool::WorkingSet * ws, osgEarth::ProgressCallback * progress) Zeile 345 C++
osgEarth.dll!osgEarth::ElevationPool::sampleMapCoords(std::vector<osg::Vec4d,std::allocator<osg::Vec4d>> & points, osgEarth::ElevationPool::WorkingSet * ws, osgEarth::ProgressCallback * progress) Zeile 553 C++
osgEarth.dll!osgEarth::NormalMapGenerator::createNormalMap(const osgEarth::TileKey & key, const osgEarth::Map * map, void * ws, osgEarth::ProgressCallback * progress) Zeile 265 C++
osgEarth.dll!osgEarth::ElevationTexture::generateNormalMap(const osgEarth::Map * map, void * workingSet, osgEarth::ProgressCallback * progress) Zeile 168 C++
osgEarth.dll!osgEarth::TerrainTileModelFactory::addElevation(osgEarth::TerrainTileModel * model, const osgEarth::Map * map, const osgEarth::TileKey & key, const osgEarth::CreateTileManifest & manifest, unsigned int border, osgEarth::ProgressCallback * progress) Zeile 570 C++
osgEarth.dll!osgEarth::TerrainTileModelFactory::createTileModel(const osgEarth::Map * map, const osgEarth::TileKey & key, const osgEarth::CreateTileManifest & manifest, const osgEarth::Util::TerrainEngineRequirements * requirements, osgEarth::ProgressCallback * progress) Zeile 239 C++
osgEarth.dll!osgEarth::TerrainEngineNode::createTileModel(const osgEarth::Map * map, const osgEarth::TileKey & key, const osgEarth::CreateTileManifest & manifest, osgEarth::ProgressCallback * progress) Zeile 228 C++
osgdb_osgearth_engine_rex.dll!osgEarth::REX::LoadTileData::run(osgEarth::ProgressCallback * progress) Zeile 80 C++
osgdb_osgearth_engine_rex.dll!osgEarth::REX::PagerLoader::runAndRelease(int requestUID) Zeile 583 C++
osgdb_osgearth_engine_rex.dll!osgEarth::REX::PagerLoaderAgent::readNode(const std::string & uri, const osgDB::Options * dboptions) Zeile 638 C++
osgDB.dll!osgDB::Registry::ReadNodeFunctor::doRead(osgDB::ReaderWriter & rw) Zeile 969 C++
osgDB.dll!osgDB::Registry::read(const osgDB::Registry::ReadFunctor & readFunctor) Zeile 1195 C++
osgDB.dll!osgDB::Registry::readImplementation(const osgDB::Registry::ReadFunctor & readFunctor, osgDB::Options::CacheHintOptions cacheHint) Zeile 1312 C++
osgDB.dll!osgDB::Registry::readNodeImplementation(const std::string & fileName, const osgDB::Options * options) Zeile 1484 C++
osgDB.dll!osgDB::Registry::readNode(const std::string & fileName, const osgDB::Options * options, bool buildKdTreeIfRequired) Zeile 239 C++
osgDB.dll!osgDB::DatabasePager::DatabaseThread::run() Zeile 858 C++
OpenThreads.dll!OpenThreads::ThreadPrivateActions::StartThread(void * data) Zeile 114 C++
Benedikt
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: issue with removing gdal elevation layer

Thank you - I opened a defect for this.
https://github.com/gwaldron/osgearth/issues/1665
Glenn Waldron / Pelican Mapping
Tension Tension
Reply | Threaded
Open this post in threaded view
|

Re: issue with removing gdal elevation layer

In reply to this post by benedikt.schwarz
Hi!

I have a similar problem, but with calling setVisible on elevation layer. Fix from github doesn't help for that.
Here is the call stack:

osgEarthd.dll!osgEarth::ElevationPool::refresh(const osgEarth::Map * map) Line 186
osgEarthd.dll!osgEarth::ElevationPool::sync(const osgEarth::Map * map, osgEarth::ElevationPool::WorkingSet * ws) Line 144
osgEarthd.dll!osgEarth::ElevationPool::getTile(const osgEarth::TileKey & tilekey, bool acceptLowerRes, osg::ref_ptr<osgEarth::ElevationTexture> & out_tex, osgEarth::ElevationPool::WorkingSet * ws, osgEarth::ProgressCallback * progress) Line 860
osgEarthd.dll!osgEarth::TerrainTileModelFactory::addElevation(osgEarth::TerrainTileModel * model, const osgEarth::Map * map, const osgEarth::TileKey & key, const osgEarth::CreateTileManifest & manifest, unsigned int border, osgEarth::ProgressCallback * progress) Line 558
osgEarthd.dll!osgEarth::TerrainTileModelFactory::createTileModel(const osgEarth::Map * map, const osgEarth::TileKey & key, const osgEarth::CreateTileManifest & manifest, const osgEarth::Util::TerrainEngineRequirements * requirements, osgEarth::ProgressCallback * progress) Line 239
osgEarthd.dll!osgEarth::TerrainEngineNode::createTileModel(const osgEarth::Map * map, const osgEarth::TileKey & key, const osgEarth::CreateTileManifest & manifest, osgEarth::ProgressCallback * progress) Line 228
osgdb_osgearth_engine_rexd.dll!osgEarth::REX::LoadTileData::run(osgEarth::ProgressCallback * progress) Line 80
osgdb_osgearth_engine_rexd.dll!osgEarth::REX::PagerLoader::runAndRelease(int requestUID) Line 583
osgdb_osgearth_engine_rexd.dll!osgEarth::REX::PagerLoaderAgent::readNode(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & uri, const osgDB::Options * dboptions) Line 638
osg161-osgDBd.dll!osgDB::Registry::ReadNodeFunctor::doRead(osgDB::ReaderWriter & rw) Line 969
osg161-osgDBd.dll!osgDB::Registry::read(const osgDB::Registry::ReadFunctor & readFunctor) Line 1195
osg161-osgDBd.dll!osgDB::Registry::readImplementation(const osgDB::Registry::ReadFunctor & readFunctor, osgDB::Options::CacheHintOptions cacheHint) Line 1312
osg161-osgDBd.dll!osgDB::Registry::readNodeImplementation(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & fileName, const osgDB::Options * options) Line 1484
osg161-osgDBd.dll!osgDB::Registry::readNode(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & fileName, const osgDB::Options * options, bool buildKdTreeIfRequired) Line 239
osg161-osgDBd.dll!osgDB::DatabasePager::DatabaseThread::run() Line 858
ot21-OpenThreadsd.dll!OpenThreads::ThreadPrivateActions::StartThread(void * data) Line 114
ucrtbased.dll!00007ffbff4c4fb8() (Unknown Source:0)
ucrtbased.dll!00007ffbff4c4bf1() (Unknown Source:0)
kernel32.dll!00007ffc40cf37e4() (Unknown Source:0)
ntdll.dll!00007ffc4376cb81() (Unknown Source:0)

Problematic line (returned profile is NULL):
maxLevel = layer->getProfile()->getEquivalentLOD(map->getProfile(), maxLevel);

osgEarth 3.1 + fix from github from issue, mentioned here.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: issue with removing gdal elevation layer

Tension,
Once the issue is logged in GitHub, please follow up in the GitHub comments so we can track it there. Thanks.
Glenn Waldron / Pelican Mapping
Tension Tension
Reply | Threaded
Open this post in threaded view
|

Re: issue with removing gdal elevation layer

Hi,

This commit fixed my issue:
https://github.com/gwaldron/osgearth/commit/21fdd6f37c9cfb3956035ffde9bded65e4c51035

Sorry, didn't notice it earlier.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: issue with removing gdal elevation layer

Ah, thanks for the follow up.
Glenn Waldron / Pelican Mapping