Skip to content

Commit

Permalink
avoid accessing QgsMapLayer::extent() from a different thread
Browse files Browse the repository at this point in the history
  • Loading branch information
uclaros authored and nyalldawson committed Jan 23, 2023
1 parent f384411 commit c0e4d07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/3d/terrain/qgsdemterraintileloader_p.cpp
Expand Up @@ -153,6 +153,7 @@ void QgsDemTerrainTileLoader::onHeightMapReady( int jobId, const QByteArray &hei

QgsDemHeightMapGenerator::QgsDemHeightMapGenerator( QgsRasterLayer *dtm, const QgsTilingScheme &tilingScheme, int resolution, const QgsCoordinateTransformContext &transformContext )
: mDtm( dtm )
, mDtmExtent( dtm ? dtm->extent() : QgsRectangle() )
, mClonedProvider( dtm ? qgis::down_cast<QgsRasterDataProvider *>( dtm->dataProvider()->clone() ) : nullptr )
, mTilingScheme( tilingScheme )
, mResolution( resolution )
Expand Down Expand Up @@ -312,11 +313,10 @@ float QgsDemHeightMapGenerator::heightAt( double x, double y )

// TODO: this is quite a primitive implementation: better to use heightmaps currently in use
int res = 1024;
QgsRectangle rect = mDtm->extent();
lazyLoadDtmCoarseData( res, rect );
lazyLoadDtmCoarseData( res, mDtmExtent );

int cellX = ( int )( ( x - rect.xMinimum() ) / rect.width() * res + .5f );
int cellY = ( int )( ( rect.yMaximum() - y ) / rect.height() * res + .5f );
int cellX = ( int )( ( x - mDtmExtent.xMinimum() ) / mDtmExtent.width() * res + .5f );
int cellY = ( int )( ( mDtmExtent.yMaximum() - y ) / mDtmExtent.height() * res + .5f );
cellX = std::clamp( cellX, 0, res - 1 );
cellY = std::clamp( cellY, 0, res - 1 );

Expand Down
3 changes: 3 additions & 0 deletions src/3d/terrain/qgsdemterraintileloader_p.h
Expand Up @@ -113,6 +113,9 @@ class QgsDemHeightMapGenerator : public QObject
//! raster used to build terrain
QgsRasterLayer *mDtm = nullptr;

//! dtm raster layer's extent in layer crs
const QgsRectangle mDtmExtent;

//! cloned provider to be used in worker thread
QgsRasterDataProvider *mClonedProvider = nullptr;

Expand Down

0 comments on commit c0e4d07

Please sign in to comment.