Skip to content
Permalink
Browse files

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

  • Loading branch information
PeterPetrik authored and nyalldawson committed Oct 9, 2020
1 parent 1258afe commit 9d0618631597b506b23486a91bba4f56203b8a9e
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
@@ -27,6 +27,7 @@
#include "qgsterraingenerator.h"

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

///@cond PRIVATE

@@ -268,21 +269,27 @@ void QgsDemHeightMapGenerator::waitForFinished()
}
}

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 );
@@ -32,6 +32,7 @@
#include <QtConcurrent/QtConcurrentRun>
#include <QFutureWatcher>
#include <QElapsedTimer>
#include <QMutex>

#include "qgschunknode_p.h"
#include "qgsrectangle.h"
@@ -133,6 +134,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 9d06186

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