Skip to content
Permalink
Browse files
Fix crashes on exit due to wkt geometry cache
  • Loading branch information
nyalldawson committed Nov 16, 2021
1 parent bfab3f7 commit eb223fd9e468a7430836b8fa09a2b1a5f9d8ab51
Showing with 7 additions and 9 deletions.
  1. +7 −9 src/core/geometry/qgsgeometry.cpp
@@ -159,19 +159,17 @@ bool QgsGeometry::isNull() const
return !d->geometry;
}

typedef QCache< QString, QgsGeometry > WktCache;
Q_GLOBAL_STATIC_WITH_ARGS( WktCache, sWktCache, ( 2000 ) ) // store up to 2000 geometries
Q_GLOBAL_STATIC( QMutex, sWktMutex )

QgsGeometry QgsGeometry::fromWkt( const QString &wkt )
{
static QCache< QString, QgsGeometry > sWktCache( 2000 ); // store up to 2000 geometries
static QReadWriteLock sCacheLock;

QgsReadWriteLocker lock( sCacheLock, QgsReadWriteLocker::Read );
if ( const QgsGeometry *cached = sWktCache.object( wkt ) )
QMutexLocker lock( sWktMutex() );
if ( const QgsGeometry *cached = sWktCache()->object( wkt ) )
return *cached;
lock.unlock();

const QgsGeometry result( QgsGeometryFactory::geomFromWkt( wkt ) );
lock.changeMode( QgsReadWriteLocker::Write );
sWktCache.insert( wkt, new QgsGeometry( result ), 1 );
sWktCache()->insert( wkt, new QgsGeometry( result ), 1 );
return result;
}

0 comments on commit eb223fd

Please sign in to comment.