From c6622732c65b018c866e8af9ff1337e5c48cf907 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 4 Nov 2020 02:18:21 +0000 Subject: [PATCH] Fix potential crash on QGIS exit under rare circumstances --- src/app/qgisapp.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 34f10c8cfbc4..bc3830c0b363 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -11462,23 +11462,24 @@ void QgisApp::projectTemporalRangeChanged() if ( currentLayer->dataProvider() ) { - QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata( - currentLayer->providerType() ); - - QVariantMap uri = metadata->decodeUri( currentLayer->dataProvider()->dataSourceUri() ); - - if ( uri.contains( QStringLiteral( "temporalSource" ) ) && - uri.value( QStringLiteral( "temporalSource" ) ).toString() == QLatin1String( "project" ) ) + if ( QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata( + currentLayer->providerType() ) ) { - QgsDateTimeRange range = QgsProject::instance()->timeSettings()->temporalRange(); - if ( range.begin().isValid() && range.end().isValid() ) + QVariantMap uri = metadata->decodeUri( currentLayer->dataProvider()->dataSourceUri() ); + + if ( uri.contains( QStringLiteral( "temporalSource" ) ) && + uri.value( QStringLiteral( "temporalSource" ) ).toString() == QLatin1String( "project" ) ) { - QString time = range.begin().toString( Qt::ISODateWithMs ) + '/' + - range.end().toString( Qt::ISODateWithMs ); + QgsDateTimeRange range = QgsProject::instance()->timeSettings()->temporalRange(); + if ( range.begin().isValid() && range.end().isValid() ) + { + QString time = range.begin().toString( Qt::ISODateWithMs ) + '/' + + range.end().toString( Qt::ISODateWithMs ); - uri[ QStringLiteral( "time" ) ] = time; + uri[ QStringLiteral( "time" ) ] = time; - currentLayer->setDataSource( metadata->encodeUri( uri ), currentLayer->name(), currentLayer->providerType(), QgsDataProvider::ProviderOptions() ); + currentLayer->setDataSource( metadata->encodeUri( uri ), currentLayer->name(), currentLayer->providerType(), QgsDataProvider::ProviderOptions() ); + } } } }