Skip to content

Commit

Permalink
Use a temporary PJ_CONTEXT when destroying PJ objects, just in case t…
Browse files Browse the repository at this point in the history
…he owner context has since been deleted
  • Loading branch information
nyalldawson committed Jan 22, 2020
1 parent 2bf0e9f commit e60d0ac
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/qgscoordinatereferencesystem_p.h
Expand Up @@ -98,11 +98,24 @@ class QgsCoordinateReferenceSystemPrivate : public QSharedData
#if PROJ_VERSION_MAJOR>=6
QgsReadWriteLocker locker( mProjLock, QgsReadWriteLocker::Write );

// During destruction of PJ* objects, the errno is set in the underlying
// context. Consequently the context attached to the PJ* must still exist !
// Which is not necessarily the case currently unfortunately. So
// create a temporary dummy context, and attach it to the PJ* before destroying
// it
PJ_CONTEXT *tmpContext = proj_context_create();
for ( auto it = mProjObjects.begin(); it != mProjObjects.end(); ++it )
{
proj_assign_context( it.value(), tmpContext );
proj_destroy( it.value() );
}
mProjObjects.clear();
if ( mPj )
{
proj_assign_context( mPj.get(), tmpContext );
mPj.reset();
}
proj_context_destroy( tmpContext );
#else
OSRDestroySpatialReference( mCRS );
#endif
Expand Down

0 comments on commit e60d0ac

Please sign in to comment.