Skip to content

Commit

Permalink
Fix crash when unloading multiple layers from a project
Browse files Browse the repository at this point in the history
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 b67d661
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/app/qgsstatisticalsummarydockwidget.cpp
Expand Up @@ -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() );
}
}

Expand Down

0 comments on commit b67d661

Please sign in to comment.