Skip to content
Permalink
Browse files

Use Q_GLOBAL_STATIC for QMap storing QgsCoordinateReference system

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 187d2a7ac50417f3a50b2cf653dc2363ed9428a2
Showing with 7 additions and 6 deletions.
  1. +7 −5 src/core/geocoding/qgsgooglemapsgeocoder.cpp
  2. +0 −1 src/core/geocoding/qgsgooglemapsgeocoder.h
@@ -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 )
@@ -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;
}
@@ -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>();
}

@@ -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;
}
@@ -114,7 +114,6 @@ class CORE_EXPORT QgsGoogleMapsGeocoder : public QgsGeocoderInterface
QString mEndpoint;

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

};

0 comments on commit 187d2a7

Please sign in to comment.