Skip to content

Commit

Permalink
Delete raster provider also if invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Dec 18, 2012
1 parent 1ea0f11 commit ffd6508
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/app/qgisapp.cpp
Expand Up @@ -3585,6 +3585,9 @@ bool QgisApp::openLayer( const QString & fileName, bool allowInteractive )
}
// TODO - should we really call isValidRasterFileName() before addRasterLayer()
// this results in 2 calls to GDALOpen()
// I think (Radim) that it is better to test only first if valid,
// addRasterLayer() is really trying to add layer and gives error if fails
//
// if ( addRasterLayer( fileName, fileInfo.completeBaseName() ) )
// {
// ok = true );
Expand Down Expand Up @@ -7546,8 +7549,6 @@ QgsRasterLayer* QgisApp::addRasterLayer( QString const & rasterFile, QString con

// The first layer loaded is not useful in that case. The user can select it in
// the list if he wants to load it.
// TODO fix this - provider is not deleted in ~QgsRasterLayer()
delete layer->dataProvider();
delete layer;
layer = 0;
}
Expand Down Expand Up @@ -7723,8 +7724,6 @@ bool QgisApp::addRasterLayers( QStringList const &theFileNameQStringList, bool g

// The first layer loaded is not useful in that case. The user can select it in
// the list if he wants to load it.
// TODO fix this - provider is not deleted in ~QgsRasterLayer()
delete layer->dataProvider();
delete layer;
layer = 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -193,8 +193,7 @@ QgsRasterLayer::QgsRasterLayer( const QString & uri,
QgsRasterLayer::~QgsRasterLayer()
{
mValid = false;
// TODO fix this - provider is not deleted!
//delete mDataProvider; // deleted by pipe
// Note: provider and other interfaces are owned and deleted by pipe
}

//////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1603,13 +1602,14 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
}
QgsDebugMsg( "Data provider created" );

// Set data provider into pipe even if not valid so that it is deleted with pipe (with layer)
mPipe.set( mDataProvider );
if ( !mDataProvider->isValid() )
{
setError( mDataProvider->error() );
appendError( ERR( tr( "Provider is not valid (provider: %1, URI: %2" ).arg( mProviderKey ).arg( mDataSource ) ) );
return;
}
mPipe.set( mDataProvider );

if ( provider == "gdal" )
{
Expand Down
4 changes: 4 additions & 0 deletions src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -132,12 +132,16 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )
// "ERROR 4: `pok.tif' does not exist in the file system, and is not recognised as a supported dataset name."
// To avoid this message, we test first if the file exists at all.
// This should be done better adding static create() method or something like that
// TODO: Cannot test for file existence, for example NetCDF with sublayers
// is using URI: NETCDF:"/path/to/file.cdf":layer1
/*
if ( !QFile::exists( uri ) )
{
QString msg = QString( "File does not exist: %1" ).arg( dataSourceUri() );
appendError( ERR( msg ) );
return;
}
*/
}

QString gdalUri = dataSourceUri();
Expand Down

0 comments on commit ffd6508

Please sign in to comment.