Skip to content

Commit 984d1f2

Browse files
author
Hugo Mercier
committed
Fix a crash when trying to removeMapLayer a null pointer
1 parent 3755c3b commit 984d1f2

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/core/qgsmaplayerregistry.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,18 @@ void QgsMapLayerRegistry::removeMapLayers( const QList<QgsMapLayer*>& layers )
131131

132132
Q_FOREACH ( QgsMapLayer* layer, layers )
133133
{
134-
layerIds << layer->id();
134+
if ( layer )
135+
layerIds << layer->id();
135136
}
136137

137138
emit layersWillBeRemoved( layerIds );
138139
emit layersWillBeRemoved( layers );
139140

140141
Q_FOREACH ( QgsMapLayer* lyr, layers )
141142
{
143+
if ( !lyr )
144+
continue;
145+
142146
QString myId( lyr->id() );
143147
if ( mOwnedLayers.contains( lyr ) )
144148
{

src/core/qgsmaplayerregistry.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject
129129
* The layers being removed are deleted as well as the registry
130130
* table entries.
131131
*
132-
* @param layers The layers to remove
132+
* @param layers The layers to remove. Null pointers are ignored
133133
*
134134
* @note As a side-effect QgsProject is made dirty.
135135
*/
@@ -159,7 +159,7 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject
159159
* The layer being removed is deleted as well as the registry
160160
* table entry.
161161
*
162-
* @param layer The layer to remove
162+
* @param layer The layer to remove. Nothing happens if the pointer is null
163163
*
164164
* @note As a side-effect QgsProject is made dirty.
165165
*/

0 commit comments

Comments
 (0)