Skip to content

Commit

Permalink
GeoHeightField: underlying heightfield should be const to prevent cac…
Browse files Browse the repository at this point in the history
…he corruption
  • Loading branch information
gwaldron committed Oct 23, 2018
1 parent 3dd9319 commit e8b6ba8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 38 deletions.
18 changes: 9 additions & 9 deletions src/osgEarth/ElevationLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,14 +650,7 @@ ElevationLayer::createHeightField(const TileKey& key,
return GeoHeightField::INVALID;
}

// write to mem cache if needed:
if ( result.valid() && !fromMemCache && _memCache.valid() )
{
CacheBin* bin = _memCache->getOrCreateDefaultBin();
bin->write(cacheKey, result.getHeightField(), 0L);
}

// post-processing:
// post-processing -- must be done before caching because it may alter the heightfield data
if ( result.valid() )
{
if ( options().noDataPolicy() == NODATA_MSL )
Expand All @@ -677,13 +670,20 @@ ElevationLayer::createHeightField(const TileKey& key,
}

HeightFieldUtils::resolveInvalidHeights(
result.getHeightField(),
hf.get(),
result.getExtent(),
NO_DATA_VALUE,
geoid );
}
}

// write to mem cache if needed:
if ( result.valid() && !fromMemCache && _memCache.valid() )
{
CacheBin* bin = _memCache->getOrCreateDefaultBin();
bin->write(cacheKey, result.getHeightField(), 0L);
}

return result;
}

Expand Down
7 changes: 0 additions & 7 deletions src/osgEarth/GeoData
Original file line number Diff line number Diff line change
Expand Up @@ -826,16 +826,9 @@ namespace osgEarth
* Gets a pointer to the underlying OSG heightfield.
*/
const osg::HeightField* getHeightField() const;
osg::HeightField* getHeightField();

//! Normal map
const NormalMap* getNormalMap() const;
NormalMap* getNormalMap();

/**
* Gets a pointer to the underlying OSG heightfield, and releases the internal reference.
*/
osg::HeightField* takeHeightField();

/**
* Gets the X interval of this GeoHeightField
Expand Down
18 changes: 0 additions & 18 deletions src/osgEarth/GeoData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2664,24 +2664,6 @@ GeoHeightField::getHeightField() const
return _heightField.get();
}

osg::HeightField*
GeoHeightField::getHeightField()
{
return _heightField.get();
}

osg::HeightField*
GeoHeightField::takeHeightField()
{
return _heightField.release();
}

NormalMap*
GeoHeightField::getNormalMap()
{
return _normalMap.get();
}

const NormalMap*
GeoHeightField::getNormalMap() const
{
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarth/TileSource
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ namespace osgEarth
* image with one 32-bit channel and call storeImage.)
*/
virtual bool storeHeightField(const TileKey& key,
osg::HeightField* hf,
const osg::HeightField* hf,
ProgressCallback* progress);

public:
Expand Down
4 changes: 2 additions & 2 deletions src/osgEarth/TileSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ TileSource::createHeightField(const TileKey& key,

bool
TileSource::storeHeightField(const TileKey& key,
osg::HeightField* hf,
ProgressCallback* progress)
const osg::HeightField* hf,
ProgressCallback* progress)
{
if (getStatus().isError() || hf == 0L )
return 0L;
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarthDrivers/colorramp/ColorRampTileSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ColorRampTileSource : public TileSource
GeoHeightField geoHF = _layer->createHeightField(key, progress);
if (geoHF.valid())
{
osg::HeightField* hf = geoHF.getHeightField();
const osg::HeightField* hf = geoHF.getHeightField();
osg::Image* image = new osg::Image();
image->allocateImage(hf->getNumColumns(),hf->getNumRows(),1, GL_RGBA, GL_UNSIGNED_BYTE);
memset(image->data(), 0, image->getImageSizeInBytes());
Expand Down

0 comments on commit e8b6ba8

Please sign in to comment.