Skip to content
Permalink
Browse files

Fix potential crash on QGIS exit under rare circumstances

This is only triggered when a provider attached to a layer from the
current project does not implement provider metadata

Fixes #39776
  • Loading branch information
nyalldawson committed Nov 4, 2020
1 parent 1fd572f commit 174d30c5d9d47bac5734ec3d8ed34946809a9dd2
Showing with 14 additions and 13 deletions.
  1. +14 −13 src/app/qgisapp.cpp
@@ -11530,23 +11530,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() );
}
}
}
}

0 comments on commit 174d30c

Please sign in to comment.
You can’t perform that action at this time.