Skip to content
Permalink
Browse files

Don't clone PJ when detaching QgsCoordinateReferenceSystemPrivate

Because in all cases when we are detaching it is because the CRS is
changing, and we will be creating a new PJ anyway
  • Loading branch information
nyalldawson committed Jan 21, 2020
1 parent 10c9b2a commit f9bc99080b014892fe96110ce8025e95bacfc38c
Showing with 25 additions and 32 deletions.
  1. +25 −32 src/core/qgscoordinatereferencesystem_p.h
@@ -74,13 +74,7 @@ class QgsCoordinateReferenceSystemPrivate : public QSharedData
, mAxisInvertedDirty( other.mAxisInvertedDirty )
, mAxisInverted( other.mAxisInverted )
{
#if PROJ_VERSION_MAJOR>=6
if ( mIsValid )
{
if ( PJ *obj = other.threadLocalProjObject() )
mPj.reset( proj_clone( QgsProjContext::get(), obj ) );
}
#else
#if PROJ_VERSION_MAJOR<6
if ( mIsValid )
{
mCRS = OSRClone( other.mCRS );
@@ -96,25 +90,7 @@ 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 );
cleanPjObjects();
#else
OSRDestroySpatialReference( mCRS );
#endif
@@ -156,18 +132,35 @@ class QgsCoordinateReferenceSystemPrivate : public QSharedData
QgsProjUtils::proj_pj_unique_ptr mPj;
PJ_CONTEXT *mPjParentContext = nullptr;

public:

void setPj( QgsProjUtils::proj_pj_unique_ptr obj )
void cleanPjObjects()
{
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 )
{
PJ_CONTEXT *tmpContext = proj_context_create();
proj_assign_context( mPj.get(), tmpContext );
mPj.reset();
proj_context_destroy( tmpContext );
}
proj_context_destroy( tmpContext );
}

public:

void setPj( QgsProjUtils::proj_pj_unique_ptr obj )
{
QgsReadWriteLocker locker( mProjLock, QgsReadWriteLocker::Write );
cleanPjObjects();

mPj = std::move( obj );
mPjParentContext = QgsProjContext::get();

0 comments on commit f9bc990

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