Skip to content
Permalink
Browse files

Fix memory layers with spatial index crash when rendering

Fixes #17705
  • Loading branch information
nyalldawson committed Feb 9, 2018
1 parent abcaba8 commit 2e5d538a7e1b8971325282aea7c1e1136d1b3f4b
Showing with 5 additions and 1 deletion.
  1. +5 −1 src/core/providers/memory/qgsmemoryfeatureiterator.cpp
@@ -231,13 +231,17 @@ bool QgsMemoryFeatureIterator::close()
QgsMemoryFeatureSource::QgsMemoryFeatureSource( const QgsMemoryProvider *p )
: mFields( p->mFields )
, mFeatures( p->mFeatures )
, mSpatialIndex( p->mSpatialIndex ? new QgsSpatialIndex( *p->mSpatialIndex ) : nullptr ) // just shallow copy
, mSpatialIndex( p->mSpatialIndex ? qgis::make_unique< QgsSpatialIndex >( *p->mSpatialIndex ) : nullptr ) // this is just a shallow copy, but see below...
, mSubsetString( p->mSubsetString )
, mCrs( p->mCrs )
{
mExpressionContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope( QgsProject::instance() );
mExpressionContext.setFields( mFields );

// QgsSpatialIndex is not thread safe - so make spatial index safe to use across threads by forcing a full deep copy
if ( mSpatialIndex )
mSpatialIndex->detach();
}

QgsFeatureIterator QgsMemoryFeatureSource::getFeatures( const QgsFeatureRequest &request )

0 comments on commit 2e5d538

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