[BUGFIX] QgsMapLayerRegistry: Check layers before removed

Probably fixed #15088 Segmentation fault when using layersRemoved SIGNAL
This commit is contained in:
rldhont 2016-06-23 14:49:13 +02:00
parent 009fbc6362
commit 5daa546f6f

View File

@ -131,21 +131,23 @@ void QgsMapLayerRegistry::removeMapLayers( const QList<QgsMapLayer*>& layers )
return; return;
QStringList layerIds; QStringList layerIds;
QList<QgsMapLayer*> layerList;
Q_FOREACH ( QgsMapLayer* layer, layers ) Q_FOREACH ( QgsMapLayer* layer, layers )
{ {
if ( layer ) // check layer and the registry contains it
if ( layer && mMapLayers.contains( layer->id() ) )
{
layerIds << layer->id(); layerIds << layer->id();
layerList << layer;
}
} }
emit layersWillBeRemoved( layerIds ); emit layersWillBeRemoved( layerIds );
emit layersWillBeRemoved( layers ); emit layersWillBeRemoved( layerList );
Q_FOREACH ( QgsMapLayer* lyr, layers ) Q_FOREACH ( QgsMapLayer* lyr, layerList )
{ {
if ( !lyr )
continue;
QString myId( lyr->id() ); QString myId( lyr->id() );
emit layerWillBeRemoved( myId ); emit layerWillBeRemoved( myId );
emit layerWillBeRemoved( lyr ); emit layerWillBeRemoved( lyr );