From b94143fb1c3f5392ade43ff0c1f130580881fedf Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Tue, 17 Sep 2024 11:21:57 +0700 Subject: [PATCH] Fix multi-editing can lead to crash --- src/core/featuremodel.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/featuremodel.cpp b/src/core/featuremodel.cpp index 41ead17522..71cca1f0d3 100644 --- a/src/core/featuremodel.cpp +++ b/src/core/featuremodel.cpp @@ -533,16 +533,19 @@ bool FeatureModel::save() case MultiFeatureModel: { - for ( QgsFeature &feature : mFeatures ) + // We need to copy these members as the first feature updated triggers a refresh of the selected features, leading to changes in feature model members + const QgsFeature referenceFeature = mFeature; + const QList attributesAllowEdit = mAttributesAllowEdit; + QList features = mFeatures; + for ( QgsFeature &feature : features ) { - for ( int i = 0; i < mFeature.attributes().count(); i++ ) + for ( int i = 0; i < referenceFeature.attributes().count(); i++ ) { - if ( !mAttributesAllowEdit[i] ) + if ( !attributesAllowEdit[i] ) continue; - feature.setAttribute( i, mFeature.attributes().at( i ) ); + feature.setAttribute( i, referenceFeature.attributes().at( i ) ); } - if ( !mLayer->updateFeature( feature ) ) { QgsMessageLog::logMessage( tr( "Cannot update feature" ), QStringLiteral( "QField" ), Qgis::Warning );