Skip to content
Permalink
Browse files
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)
  • Loading branch information
nyalldawson committed May 3, 2018
1 parent f5601d5 commit b67d661a5b727a3fff9ffb88f4b5cd3ae3d655db
Showing with 12 additions and 8 deletions.
  1. +12 −8 src/app/qgsstatisticalsummarydockwidget.cpp
@@ -155,30 +155,34 @@ void QgsStatisticalSummaryDockWidget::refreshStatistics()
if ( ok )
{
int featureCount = selectedOnly ? mLayer->selectedFeatureCount() : mLayer->featureCount();
mGatherer = new QgsStatisticsValueGatherer( mLayer, fit, featureCount, sourceFieldExp );
std::unique_ptr< QgsStatisticsValueGatherer > gatherer = qgis::make_unique< QgsStatisticsValueGatherer >( mLayer, fit, featureCount, sourceFieldExp );
switch ( mFieldType )
{
case DataType::Numeric:
connect( mGatherer, &QgsStatisticsValueGatherer::taskCompleted, this, &QgsStatisticalSummaryDockWidget::updateNumericStatistics );
connect( gatherer.get(), &QgsStatisticsValueGatherer::taskCompleted, this, &QgsStatisticalSummaryDockWidget::updateNumericStatistics );
break;
case DataType::String:
connect( mGatherer, &QgsStatisticsValueGatherer::taskCompleted, this, &QgsStatisticalSummaryDockWidget::updateStringStatistics );
connect( gatherer.get(), &QgsStatisticsValueGatherer::taskCompleted, this, &QgsStatisticalSummaryDockWidget::updateStringStatistics );
break;
case DataType::DateTime:
connect( mGatherer, &QgsStatisticsValueGatherer::taskCompleted, this, &QgsStatisticalSummaryDockWidget::updateDateTimeStatistics );
connect( gatherer.get(), &QgsStatisticsValueGatherer::taskCompleted, this, &QgsStatisticalSummaryDockWidget::updateDateTimeStatistics );
break;
default:
break;
//don't know how to handle stats for this field!
mStatisticsTable->setRowCount( 0 );
return;
}
connect( mGatherer, &QgsStatisticsValueGatherer::progressChanged, mCalculatingProgressBar, &QProgressBar::setValue );
connect( mCancelButton, &QPushButton::clicked, mGatherer, &QgsStatisticsValueGatherer::cancel );
connect( gatherer.get(), &QgsStatisticsValueGatherer::progressChanged, mCalculatingProgressBar, &QProgressBar::setValue );
connect( gatherer.get(), &QgsStatisticsValueGatherer::taskTerminated, this, &QgsStatisticalSummaryDockWidget::gathererFinished );
connect( mCancelButton, &QPushButton::clicked, gatherer.get(), &QgsStatisticsValueGatherer::cancel );
mCalculatingProgressBar->setMinimum( 0 );
mCalculatingProgressBar->setMaximum( featureCount > 0 ? 100 : 0 );
mCalculatingProgressBar->setValue( 0 );
mCancelButton->show();
mCalculatingProgressBar->show();

QgsApplication::taskManager()->addTask( mGatherer );
mGatherer = gatherer.get();
QgsApplication::taskManager()->addTask( gatherer.release() );
}
}

0 comments on commit b67d661

Please sign in to comment.