Skip to content

Commit

Permalink
Merge pull request #2556 from mhugo/fix_nullp
Browse files Browse the repository at this point in the history
Avoid insertion of null pointers in layer registry
  • Loading branch information
Hugo Mercier committed Dec 8, 2015
2 parents f13104b + ec20db7 commit 0f6256e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/core/qgsmaplayerregistry.cpp
Expand Up @@ -119,7 +119,7 @@ void QgsMapLayerRegistry::removeMapLayers( const QStringList& theLayerIds )
QList<QgsMapLayer*> layers;
Q_FOREACH ( const QString &myId, theLayerIds )
{
layers << mMapLayers[myId];
layers << mMapLayers.value( myId );
}

removeMapLayers( layers );
Expand Down Expand Up @@ -160,12 +160,13 @@ void QgsMapLayerRegistry::removeMapLayers( const QList<QgsMapLayer*>& layers )

void QgsMapLayerRegistry::removeMapLayer( const QString& theLayerId )
{
removeMapLayers( QList<QgsMapLayer*>() << mMapLayers[theLayerId] );
removeMapLayers( QList<QgsMapLayer*>() << mMapLayers.value( theLayerId ) );
}

void QgsMapLayerRegistry::removeMapLayer( QgsMapLayer* layer )
{
removeMapLayers( QList<QgsMapLayer*>() << layer );
if ( layer )
removeMapLayers( QList<QgsMapLayer*>() << layer );
}

void QgsMapLayerRegistry::removeAllMapLayers()
Expand Down
5 changes: 5 additions & 0 deletions tests/src/python/test_qgsmaplayerregistry.py
Expand Up @@ -25,6 +25,11 @@ def test_RemoveLayerShouldNotSegFault(self):
reg = QgsMapLayerRegistry.instance()
# Should not segfault
reg.removeMapLayers(['not_exists'])
reg.removeMapLayer('not_exists2')

# check also that the removal of an unexistant layer does not insert a null layer
for k, layer in reg.mapLayers().items():
assert(layer is not None)


if __name__ == '__main__':
Expand Down

0 comments on commit 0f6256e

Please sign in to comment.