diff --git a/src/core/qgsmaplayerregistry.cpp b/src/core/qgsmaplayerregistry.cpp index e2f3a60d51f6..ae80733f6fbe 100644 --- a/src/core/qgsmaplayerregistry.cpp +++ b/src/core/qgsmaplayerregistry.cpp @@ -66,7 +66,7 @@ QgsMapLayer * QgsMapLayerRegistry::mapLayer( QString theLayerId ) QgsMapLayer * QgsMapLayerRegistry::addMapLayer( QgsMapLayer * theMapLayer, bool theEmitSignal ) { - if ( !theMapLayer->isValid() ) + if ( !theMapLayer || !theMapLayer->isValid() ) { QgsDebugMsg( "cannot add invalid layers" ); return 0;