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?
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.