Skip to content

Commit

Permalink
Use Q_GLOBAL_STATIC for QMap storing QgsCoordinateReference system
Browse files Browse the repository at this point in the history
so that it's correctly torn down before QgsApplication

Because we can't clean up QgsCoordinateReferenceSystem objects
after QgsApplication tear down

Fixes crash on exit of google maps geocoder test
  • Loading branch information
nyalldawson committed Feb 8, 2021
1 parent 1cdaa4e commit 187d2a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/core/geocoding/qgsgooglemapsgeocoder.cpp
Expand Up @@ -26,7 +26,9 @@
#include <QJsonObject>

QReadWriteLock QgsGoogleMapsGeocoder::sMutex;
QMap< QUrl, QList< QgsGeocoderResult > > QgsGoogleMapsGeocoder::sCachedResults;

typedef QMap< QUrl, QList< QgsGeocoderResult > > CachedGeocodeResult;
Q_GLOBAL_STATIC( CachedGeocodeResult, sCachedResults )


QgsGoogleMapsGeocoder::QgsGoogleMapsGeocoder( const QString &apiKey, const QString &regionBias )
Expand Down Expand Up @@ -87,8 +89,8 @@ QList<QgsGeocoderResult> QgsGoogleMapsGeocoder::geocodeString( const QString &st
const QUrl url = requestUrl( string, bounds );

QgsReadWriteLocker locker( sMutex, QgsReadWriteLocker::Read );
auto it = sCachedResults.constFind( url );
if ( it != sCachedResults.constEnd() )
auto it = sCachedResults()->constFind( url );
if ( it != sCachedResults()->constEnd() )
{
return *it;
}
Expand Down Expand Up @@ -138,7 +140,7 @@ QList<QgsGeocoderResult> QgsGoogleMapsGeocoder::geocodeString( const QString &st
const QVariantList results = res.value( QStringLiteral( "results" ) ).toList();
if ( results.empty() )
{
sCachedResults.insert( url, QList<QgsGeocoderResult>() );
sCachedResults()->insert( url, QList<QgsGeocoderResult>() );
return QList<QgsGeocoderResult>();
}

Expand All @@ -148,7 +150,7 @@ QList<QgsGeocoderResult> QgsGoogleMapsGeocoder::geocodeString( const QString &st
{
matches << jsonToResult( result.toMap() );
}
sCachedResults.insert( url, matches );
sCachedResults()->insert( url, matches );

return matches;
}
Expand Down
1 change: 0 additions & 1 deletion src/core/geocoding/qgsgooglemapsgeocoder.h
Expand Up @@ -114,7 +114,6 @@ class CORE_EXPORT QgsGoogleMapsGeocoder : public QgsGeocoderInterface
QString mEndpoint;

static QReadWriteLock sMutex;
static QMap< QUrl, QList< QgsGeocoderResult > > sCachedResults;

};

Expand Down

0 comments on commit 187d2a7

Please sign in to comment.