Skip to content
Permalink
Browse files

fix crashes in QGIS 3D, mostly directly at project load

  • Loading branch information
github-actions authored and nyalldawson committed Oct 11, 2020
1 parent 3686e01 commit aa014d9362f77b4873faa43a2d18c0c6304ab97b
Showing with 17 additions and 7 deletions.
  1. +14 −7 src/3d/terrain/qgsdemterraintileloader_p.cpp
  2. +3 −0 src/3d/terrain/qgsdemterraintileloader_p.h
@@ -25,6 +25,7 @@
#include "qgsterraintileentity_p.h"

#include <Qt3DRender/QGeometryRenderer>
#include <QMutexLocker>

///@cond PRIVATE

@@ -265,21 +266,27 @@ QByteArray QgsDemHeightMapGenerator::renderSynchronously( int x, int y, int z )
return data;
}

float QgsDemHeightMapGenerator::heightAt( double x, double y )
void QgsDemHeightMapGenerator::lazyLoadDtmCoarseData( int res, const QgsRectangle &rect )
{
if ( !mDtm )
return 0; // TODO: calculate heights for online DTM

// TODO: this is quite a primitive implementation: better to use heightmaps currently in use
int res = 1024;
QgsRectangle rect = mDtm->extent();
QMutexLocker locker( &mLazyLoadDtmCoarseDataMutex );
if ( mDtmCoarseData.isEmpty() )
{
std::unique_ptr< QgsRasterBlock > block( mDtm->dataProvider()->block( 1, rect, res, res ) );
block->convert( Qgis::Float32 );
mDtmCoarseData = block->data();
mDtmCoarseData.detach(); // make a deep copy
}
}

float QgsDemHeightMapGenerator::heightAt( double x, double y )
{
if ( !mDtm )
return 0; // TODO: calculate heights for online DTM

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

int cellX = ( int )( ( x - rect.xMinimum() ) / rect.width() * res + .5f );
int cellY = ( int )( ( rect.yMaximum() - y ) / rect.height() * res + .5f );
@@ -30,6 +30,7 @@
#include <QtConcurrent/QtConcurrentRun>
#include <QFutureWatcher>
#include <QElapsedTimer>
#include <QMutex>

#include "qgsrectangle.h"
#include "qgsterraintileloader_p.h"
@@ -129,6 +130,8 @@ class QgsDemHeightMapGenerator : public QObject

QHash<QFutureWatcher<QByteArray>*, JobData> mJobs;

void lazyLoadDtmCoarseData( int res, const QgsRectangle &rect );
mutable QMutex mLazyLoadDtmCoarseDataMutex;
//! used for height queries
QByteArray mDtmCoarseData;
};

0 comments on commit aa014d9

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