Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in single band pseudo color renderer #7442

Merged
merged 5 commits into from
Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/3d/terrain/qgsdemterraintileloader_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static QByteArray _readDtmData( QgsRasterDataProvider *provider, const QgsRectan
projector->setInput( provider );
input = projector.get();
}
QgsRasterBlock *block = input->block( 1, extent, res, res );
std::unique_ptr< QgsRasterBlock > block( input->block( 1, extent, res, res ) );

QByteArray data;
if ( block )
Expand All @@ -183,8 +183,6 @@ static QByteArray _readDtmData( QgsRasterDataProvider *provider, const QgsRectan
floatData[i] = std::numeric_limits<float>::quiet_NaN();
}
}

delete block;
}
return data;
}
Expand Down Expand Up @@ -227,15 +225,14 @@ QByteArray QgsDemHeightMapGenerator::renderSynchronously( int x, int y, int z )
QgsRectangle fullExtent = mTilingScheme.tileToExtent( 0, 0, 0 );
extent = extent.intersect( fullExtent );

QgsRasterBlock *block = mDtm->dataProvider()->block( 1, extent, mResolution, mResolution );
std::unique_ptr< QgsRasterBlock > block( mDtm->dataProvider()->block( 1, extent, mResolution, mResolution ) );

QByteArray data;
if ( block )
{
block->convert( Qgis::Float32 ); // currently we expect just floats
data = block->data();
data.detach(); // this should make a deep copy
delete block;
}

return data;
Expand All @@ -248,11 +245,10 @@ float QgsDemHeightMapGenerator::heightAt( double x, double y )
QgsRectangle rect = mDtm->extent();
if ( mDtmCoarseData.isEmpty() )
{
QgsRasterBlock *block = mDtm->dataProvider()->block( 1, rect, res, res );
std::unique_ptr< QgsRasterBlock > block( mDtm->dataProvider()->block( 1, rect, res, res ) );
block->convert( Qgis::Float32 );
mDtmCoarseData = block->data();
mDtmCoarseData.detach(); // make a deep copy
delete block;
}

int cellX = ( int )( ( x - rect.xMinimum() ) / rect.width() * res + .5f );
Expand Down
17 changes: 6 additions & 11 deletions src/analysis/raster/qgsrastercalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int QgsRasterCalculator::processCalculation( QgsFeedback *feedback )
{
//prepare search string / tree
QString errorString;
QgsRasterCalcNode *calcNode = QgsRasterCalcNode::parseRasterCalcString( mFormulaString, errorString );
std::unique_ptr< QgsRasterCalcNode > calcNode( QgsRasterCalcNode::parseRasterCalcString( mFormulaString, errorString ) );
if ( !calcNode )
{
//error
Expand All @@ -74,12 +74,11 @@ int QgsRasterCalculator::processCalculation( QgsFeedback *feedback )
{
if ( !it->raster ) // no raster layer in entry
{
delete calcNode;
qDeleteAll( inputBlocks );
return static_cast< int >( InputLayerError );
}

QgsRasterBlock *block = nullptr;
std::unique_ptr< QgsRasterBlock > block;
// if crs transform needed
if ( it->raster->crs() != mOutputCrs )
{
Expand All @@ -90,27 +89,23 @@ int QgsRasterCalculator::processCalculation( QgsFeedback *feedback )

QgsRasterBlockFeedback *rasterBlockFeedback = new QgsRasterBlockFeedback();
QObject::connect( feedback, &QgsFeedback::canceled, rasterBlockFeedback, &QgsRasterBlockFeedback::cancel );
block = proj.block( it->bandNumber, mOutputRectangle, mNumOutputColumns, mNumOutputRows, rasterBlockFeedback );
block.reset( proj.block( it->bandNumber, mOutputRectangle, mNumOutputColumns, mNumOutputRows, rasterBlockFeedback ) );
if ( rasterBlockFeedback->isCanceled() )
{
delete block;
delete calcNode;
qDeleteAll( inputBlocks );
return static_cast< int >( Canceled );
}
}
else
{
block = it->raster->dataProvider()->block( it->bandNumber, mOutputRectangle, mNumOutputColumns, mNumOutputRows );
block.reset( it->raster->dataProvider()->block( it->bandNumber, mOutputRectangle, mNumOutputColumns, mNumOutputRows ) );
}
if ( block->isEmpty() )
{
delete block;
delete calcNode;
qDeleteAll( inputBlocks );
return static_cast<int>( MemoryError );
}
inputBlocks.insert( it->ref, block );
inputBlocks.insert( it->ref, block.release() );
}

//open output dataset for writing
Expand Down Expand Up @@ -175,7 +170,7 @@ int QgsRasterCalculator::processCalculation( QgsFeedback *feedback )
}

//close datasets and release memory
delete calcNode;
calcNode.reset();
qDeleteAll( inputBlocks );
inputBlocks.clear();

Expand Down
3 changes: 3 additions & 0 deletions src/core/raster/qgscolorrampshader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ bool QgsColorRampShader::shade( double value, int *returnRedValue, int *returnGr
mLUTInitialized = true;
}

if ( mLUT.empty() )
return false;

// overflow indicates that value > maximum value + DOUBLE_DIFF_THRESHOLD
// that way idx can point to the last valid item
bool overflow = false;
Expand Down
7 changes: 2 additions & 5 deletions src/core/raster/qgsrasterchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ bool QgsRasterChecker::runTest( const QString &verifiedKey, QString verifiedUri,

int width = expectedProvider->xSize();
int height = expectedProvider->ySize();
QgsRasterBlock *expectedBlock = expectedProvider->block( band, expectedProvider->extent(), width, height );
QgsRasterBlock *verifiedBlock = verifiedProvider->block( band, expectedProvider->extent(), width, height );
std::unique_ptr< QgsRasterBlock > expectedBlock( expectedProvider->block( band, expectedProvider->extent(), width, height ) );
std::unique_ptr< QgsRasterBlock > verifiedBlock( verifiedProvider->block( band, expectedProvider->extent(), width, height ) );

if ( !expectedBlock || !expectedBlock->isValid() ||
!verifiedBlock || !verifiedBlock->isValid() )
Expand Down Expand Up @@ -182,9 +182,6 @@ bool QgsRasterChecker::runTest( const QString &verifiedKey, QString verifiedUri,
htmlTable += QLatin1String( "</table>" );

mReport += htmlTable;

delete expectedBlock;
delete verifiedBlock;
}
delete verifiedProvider;
delete expectedProvider;
Expand Down
Loading