Skip to content

Commit b67d661

Browse files
committedMay 3, 2018
Fix crash when unloading multiple layers from a project
The stats dock was holding onto a dangling pointer whenever the statistics gathering task was canceled. This meant that the next time the stats dock tried to start a calculation, it would try to cancel the dangling task pointer and crash. (cherry-picked from 350200d)
1 parent f5601d5 commit b67d661

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed
 

‎src/app/qgsstatisticalsummarydockwidget.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,30 +155,34 @@ void QgsStatisticalSummaryDockWidget::refreshStatistics()
155155
if ( ok )
156156
{
157157
int featureCount = selectedOnly ? mLayer->selectedFeatureCount() : mLayer->featureCount();
158-
mGatherer = new QgsStatisticsValueGatherer( mLayer, fit, featureCount, sourceFieldExp );
158+
std::unique_ptr< QgsStatisticsValueGatherer > gatherer = qgis::make_unique< QgsStatisticsValueGatherer >( mLayer, fit, featureCount, sourceFieldExp );
159159
switch ( mFieldType )
160160
{
161161
case DataType::Numeric:
162-
connect( mGatherer, &QgsStatisticsValueGatherer::taskCompleted, this, &QgsStatisticalSummaryDockWidget::updateNumericStatistics );
162+
connect( gatherer.get(), &QgsStatisticsValueGatherer::taskCompleted, this, &QgsStatisticalSummaryDockWidget::updateNumericStatistics );
163163
break;
164164
case DataType::String:
165-
connect( mGatherer, &QgsStatisticsValueGatherer::taskCompleted, this, &QgsStatisticalSummaryDockWidget::updateStringStatistics );
165+
connect( gatherer.get(), &QgsStatisticsValueGatherer::taskCompleted, this, &QgsStatisticalSummaryDockWidget::updateStringStatistics );
166166
break;
167167
case DataType::DateTime:
168-
connect( mGatherer, &QgsStatisticsValueGatherer::taskCompleted, this, &QgsStatisticalSummaryDockWidget::updateDateTimeStatistics );
168+
connect( gatherer.get(), &QgsStatisticsValueGatherer::taskCompleted, this, &QgsStatisticalSummaryDockWidget::updateDateTimeStatistics );
169169
break;
170170
default:
171-
break;
171+
//don't know how to handle stats for this field!
172+
mStatisticsTable->setRowCount( 0 );
173+
return;
172174
}
173-
connect( mGatherer, &QgsStatisticsValueGatherer::progressChanged, mCalculatingProgressBar, &QProgressBar::setValue );
174-
connect( mCancelButton, &QPushButton::clicked, mGatherer, &QgsStatisticsValueGatherer::cancel );
175+
connect( gatherer.get(), &QgsStatisticsValueGatherer::progressChanged, mCalculatingProgressBar, &QProgressBar::setValue );
176+
connect( gatherer.get(), &QgsStatisticsValueGatherer::taskTerminated, this, &QgsStatisticalSummaryDockWidget::gathererFinished );
177+
connect( mCancelButton, &QPushButton::clicked, gatherer.get(), &QgsStatisticsValueGatherer::cancel );
175178
mCalculatingProgressBar->setMinimum( 0 );
176179
mCalculatingProgressBar->setMaximum( featureCount > 0 ? 100 : 0 );
177180
mCalculatingProgressBar->setValue( 0 );
178181
mCancelButton->show();
179182
mCalculatingProgressBar->show();
180183

181-
QgsApplication::taskManager()->addTask( mGatherer );
184+
mGatherer = gatherer.get();
185+
QgsApplication::taskManager()->addTask( gatherer.release() );
182186
}
183187
}
184188

0 commit comments

Comments
 (0)
Please sign in to comment.