Skip to content
Permalink
Browse files

Avoid insertion of null pointers in layer registry

  • Loading branch information
mhugo committed Dec 8, 2015
1 parent 269f709 commit ec20db7adebf9a48f0c26b520c95e3e330efc710
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 ec20db7

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