Skip to content

Commit

Permalink
Don't clone PJ when detaching QgsCoordinateReferenceSystemPrivate
Browse files Browse the repository at this point in the history
Because in all cases when we are detaching it is because the CRS is
changing, and we will be creating a new PJ anyway

(cherry picked from commit 4fee29ef075b4874d6391ab4361eb436e57c5f71)
  • Loading branch information
nyalldawson committed Jan 22, 2020
1 parent 920abf3 commit 9d86fb2
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions src/core/qgscoordinatereferencesystem_p.h
Expand Up @@ -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 );
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 9d86fb2

Please sign in to comment.