Skip to content

Commit

Permalink
Prevents a crash when online features are gone
Browse files Browse the repository at this point in the history
Fixes an unreported segfault when converting an online layer
to offline if features cannot be (completely) fetched.

Funded by Boundless

(cherry-picked from 79442b6)
  • Loading branch information
elpaso authored and dakcarto committed Apr 22, 2016
1 parent 64f2903 commit 0c54862
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/core/qgsofflineediting.cpp
Expand Up @@ -142,7 +142,7 @@ bool QgsOfflineEditing::convertToOfflineProject( const QString& offlineDataPath,
layerIdMapping.insert( origLayerId, newLayer );
// remove remote layer
QgsMapLayerRegistry::instance()->removeMapLayers(
QStringList() << vl->id() );
QStringList() << origLayerId );
}
}

Expand Down Expand Up @@ -648,7 +648,16 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit
int remoteCount = remoteFeatureIds.size();
for ( int i = 0; i < remoteCount; i++ )
{
addFidLookup( db, layerId, offlineFeatureIds.at( i ), remoteFeatureIds.at( remoteCount - ( i + 1 ) ) );
// Check if the online feature has been fetched (WFS download aborted for some reason)
if ( i < offlineFeatureIds.count() )
{
addFidLookup( db, layerId, offlineFeatureIds.at( i ), remoteFeatureIds.at( remoteCount - ( i + 1 ) ) );
}
else
{
showWarning( QString( "Feature cannot be copied to the offline layer, please check if the online layer '%1' is sill accessible." ).arg( layer->name() ) );
return nullptr;
}
emit progressUpdated( featureCount++ );
}
sqlExec( db, "COMMIT" );
Expand Down

0 comments on commit 0c54862

Please sign in to comment.