Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multi-editing can lead to crash #5657

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/core/featuremodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> attributesAllowEdit = mAttributesAllowEdit;
QList<QgsFeature> 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 );
Expand Down
Loading