Skip to content

Commit

Permalink
[BUGFIX][QGIS Server] Do not cache invalid layer
Browse files Browse the repository at this point in the history
After readLayerXml, the server stored layers in cache and in registry without verifying validity.
  • Loading branch information
rldhont committed Oct 25, 2016
1 parent 6bf74b4 commit 36db42e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/server/qgshostedrdsbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ QgsMapLayer* QgsHostedRDSBuilder::createMapLayer( const QDomElement& elem,
{
rl = qobject_cast<QgsRasterLayer*>( QgsMSLayerCache::instance()->searchLayer( uri, layerName ) );
}
if ( !rl )
if ( !rl || !rl->isValid() )
{
QgsDebugMsg( "hostedrds layer not in cache, so create and insert it" );
rl = new QgsRasterLayer( uri, layerNameFromUri( uri ) );
Expand Down
4 changes: 4 additions & 0 deletions src/server/qgsserverprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement&
layer->readLayerXML( const_cast<QDomElement&>( elem ) ); //should be changed to const in QgsMapLayer
//layer->setLayerName( layerName( elem ) );

if ( !layer->isValid() )
{
return nullptr;
}
// Insert layer in registry and cache before addValueRelationLayersForLayer
if ( !QgsMapLayerRegistry::instance()->mapLayer( id ) )
QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false );
Expand Down

0 comments on commit 36db42e

Please sign in to comment.