Skip to content
Permalink
Browse files

Merge pull request #2556 from mhugo/fix_nullp

Avoid insertion of null pointers in layer registry
  • Loading branch information
mhugo committed Dec 8, 2015
2 parents f13104b + ec20db7 commit 0f6256ebcd511d736283ce6cf8528b8fbbdfcf7a
Showing with 9 additions and 3 deletions.
  1. +4 −3 src/core/qgsmaplayerregistry.cpp
  2. +5 −0 tests/src/python/test_qgsmaplayerregistry.py
@@ -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 );
@@ -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()
@@ -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__':

0 comments on commit 0f6256e

Please sign in to comment.
You can’t perform that action at this time.