Skip to content

Commit 5daa546

Browse files
committed
[BUGFIX] QgsMapLayerRegistry: Check layers before removed
Probably fixed #15088 Segmentation fault when using layersRemoved SIGNAL
1 parent 009fbc6 commit 5daa546

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/core/qgsmaplayerregistry.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,23 @@ void QgsMapLayerRegistry::removeMapLayers( const QList<QgsMapLayer*>& layers )
131131
return;
132132

133133
QStringList layerIds;
134+
QList<QgsMapLayer*> layerList;
134135

135136
Q_FOREACH ( QgsMapLayer* layer, layers )
136137
{
137-
if ( layer )
138+
// check layer and the registry contains it
139+
if ( layer && mMapLayers.contains( layer->id() ) )
140+
{
138141
layerIds << layer->id();
142+
layerList << layer;
143+
}
139144
}
140145

141146
emit layersWillBeRemoved( layerIds );
142-
emit layersWillBeRemoved( layers );
147+
emit layersWillBeRemoved( layerList );
143148

144-
Q_FOREACH ( QgsMapLayer* lyr, layers )
149+
Q_FOREACH ( QgsMapLayer* lyr, layerList )
145150
{
146-
if ( !lyr )
147-
continue;
148-
149151
QString myId( lyr->id() );
150152
emit layerWillBeRemoved( myId );
151153
emit layerWillBeRemoved( lyr );

0 commit comments

Comments
 (0)