Skip to content

Commit

Permalink
Fix thread safety of DEM height map generator
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 15, 2022
1 parent c9bcfe5 commit 9415f3e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/3d/terrain/qgsdemterraintileloader_p.cpp
Expand Up @@ -171,6 +171,8 @@ QgsDemHeightMapGenerator::~QgsDemHeightMapGenerator()

static QByteArray _readDtmData( QgsRasterDataProvider *provider, const QgsRectangle &extent, int res, const QgsCoordinateReferenceSystem &destCrs )
{
provider->moveToThread( QThread::currentThread() );

QgsEventTracing::ScopedEvent e( QStringLiteral( "3D" ), QStringLiteral( "DEM" ) );

// TODO: use feedback object? (but GDAL currently does not support cancellation anyway)
Expand Down Expand Up @@ -205,6 +207,9 @@ static QByteArray _readDtmData( QgsRasterDataProvider *provider, const QgsRectan
}
}
}

provider->moveToThread( nullptr );

return data;
}

Expand Down Expand Up @@ -235,9 +240,14 @@ int QgsDemHeightMapGenerator::render( const QgsChunkNodeId &nodeId )
connect( fw, &QFutureWatcher<QByteArray>::finished, fw, &QObject::deleteLater );
// make a clone of the data provider so it is safe to use in worker thread
if ( mDtm )
{
mClonedProvider->moveToThread( nullptr );
jd.future = QtConcurrent::run( _readDtmData, mClonedProvider, extent, mResolution, mTilingScheme.crs() );
}
else
{
jd.future = QtConcurrent::run( _readOnlineDtm, mDownloader.get(), extent, mResolution, mTilingScheme.crs(), mTransformContext );
}

fw->setFuture( jd.future );

Expand Down

0 comments on commit 9415f3e

Please sign in to comment.