Skip to content

Commit 2e5d538

Browse files
committed
Fix memory layers with spatial index crash when rendering
Fixes #17705
1 parent abcaba8 commit 2e5d538

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/core/providers/memory/qgsmemoryfeatureiterator.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,17 @@ bool QgsMemoryFeatureIterator::close()
231231
QgsMemoryFeatureSource::QgsMemoryFeatureSource( const QgsMemoryProvider *p )
232232
: mFields( p->mFields )
233233
, mFeatures( p->mFeatures )
234-
, mSpatialIndex( p->mSpatialIndex ? new QgsSpatialIndex( *p->mSpatialIndex ) : nullptr ) // just shallow copy
234+
, mSpatialIndex( p->mSpatialIndex ? qgis::make_unique< QgsSpatialIndex >( *p->mSpatialIndex ) : nullptr ) // this is just a shallow copy, but see below...
235235
, mSubsetString( p->mSubsetString )
236236
, mCrs( p->mCrs )
237237
{
238238
mExpressionContext << QgsExpressionContextUtils::globalScope()
239239
<< QgsExpressionContextUtils::projectScope( QgsProject::instance() );
240240
mExpressionContext.setFields( mFields );
241+
242+
// QgsSpatialIndex is not thread safe - so make spatial index safe to use across threads by forcing a full deep copy
243+
if ( mSpatialIndex )
244+
mSpatialIndex->detach();
241245
}
242246

243247
QgsFeatureIterator QgsMemoryFeatureSource::getFeatures( const QgsFeatureRequest &request )

0 commit comments

Comments
 (0)