Skip to content

Commit 79442b6

Browse files
committed
Prevents a crash when online features are gone
Fixes an unreported segfault when converting an online layer to offline if features cannot be (completely) fetched. Funded by Boundless
1 parent eeb9bdd commit 79442b6

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/core/qgsofflineediting.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ bool QgsOfflineEditing::convertToOfflineProject( const QString& offlineDataPath,
129129
if ( newLayer )
130130
{
131131
layerIdMapping.insert( origLayerId, newLayer );
132+
// remove remote layer
133+
QgsMapLayerRegistry::instance()->removeMapLayers(
134+
QStringList() << origLayerId );
132135
}
133136
}
134137

@@ -645,7 +648,16 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit
645648
int remoteCount = remoteFeatureIds.size();
646649
for ( int i = 0; i < remoteCount; i++ )
647650
{
648-
addFidLookup( db, layerId, offlineFeatureIds.at( i ), remoteFeatureIds.at( remoteCount - ( i + 1 ) ) );
651+
// Check if the online feature has been fetched (WFS download aborted for some reason)
652+
if ( i < offlineFeatureIds.count() )
653+
{
654+
addFidLookup( db, layerId, offlineFeatureIds.at( i ), remoteFeatureIds.at( remoteCount - ( i + 1 ) ) );
655+
}
656+
else
657+
{
658+
showWarning( QString( "Feature cannot be copied to the offline layer, please check if the online layer '%1' is sill accessible." ).arg( layer->name() ) );
659+
return nullptr;
660+
}
649661
emit progressUpdated( featureCount++ );
650662
}
651663
sqlExec( db, "COMMIT" );
@@ -654,10 +666,6 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit
654666
{
655667
showWarning( newLayer->commitErrors().join( "\n" ) );
656668
}
657-
658-
// remove remote layer
659-
QgsMapLayerRegistry::instance()->removeMapLayers(
660-
QStringList() << layer->id() );
661669
}
662670
return newLayer;
663671
}

0 commit comments

Comments
 (0)