Skip to content
Permalink
Browse files

avoid 3D crash if terrain layer is null

  • Loading branch information
vcloarec authored and nyalldawson committed Jun 2, 2020
1 parent 7b8bd80 commit 3b86c51b25b311aa06d2509339b54bb6b00e47fb
@@ -123,6 +123,9 @@ QgsChunkedEntity::~QgsChunkedEntity()

void QgsChunkedEntity::update( const SceneState &state )
{
if ( !mIsValid )
return;

QElapsedTimer t;
t.start();

@@ -399,7 +402,8 @@ void QgsChunkedEntity::startJobs()
delete entry;

QgsChunkQueueJob *job = startJob( node );
mActiveJobs.append( job );
if ( job )
mActiveJobs.append( job );
}
}

@@ -411,6 +415,8 @@ QgsChunkQueueJob *QgsChunkedEntity::startJob( QgsChunkNode *node )
QgsEventTracing::addEvent( QgsEventTracing::AsyncBegin, QStringLiteral( "3D" ), QStringLiteral( "Load " ) + node->tileId().text(), node->tileId().text() );

QgsChunkLoader *loader = mChunkLoaderFactory->createChunkLoader( node );
if ( !loader )
return nullptr;
connect( loader, &QgsChunkQueueJob::finished, this, &QgsChunkedEntity::onActiveJobFinished );
node->setLoading( loader );
return loader;
@@ -172,6 +172,8 @@ class QgsChunkedEntity : public Qt3DCore::QEntity

//! If picking is enabled, QObjectPicker objects will be assigned to chunks and pickedObject() signals fired on mouse click
bool mPickingEnabled = false;

bool mIsValid = true;
};

/// @endcond
@@ -99,6 +99,7 @@ void QgsMeshTerrainGenerator::resolveReferences( const QgsProject &project )
void QgsMeshTerrainGenerator::setLayer( QgsMeshLayer *layer )
{
mLayer = QgsMapLayerRef( layer );
mIsValid = layer != nullptr;
}

QgsMeshLayer *QgsMeshTerrainGenerator::meshLayer() const
@@ -113,11 +113,13 @@ void QgsDemTerrainGenerator::updateGenerator()
mTerrainTilingScheme = QgsTilingScheme( te, mCrs );
delete mHeightMapGenerator;
mHeightMapGenerator = new QgsDemHeightMapGenerator( dem, mTerrainTilingScheme, mResolution, mTransformContext );
mIsValid = true;
}
else
{
mTerrainTilingScheme = QgsTilingScheme();
delete mHeightMapGenerator;
mHeightMapGenerator = nullptr;
mIsValid = false;
}
}
@@ -64,6 +64,7 @@ QgsTerrainEntity::QgsTerrainEntity( int maxLevel, const Qgs3DMapSettings &map, Q
, mMap( map )
{
map.terrainGenerator()->setTerrain( this );
mIsValid = map.terrainGenerator()->isValid();

connect( &map, &Qgs3DMapSettings::showTerrainBoundingBoxesChanged, this, &QgsTerrainEntity::onShowBoundingBoxesChanged );
connect( &map, &Qgs3DMapSettings::showTerrainTilesInfoChanged, this, &QgsTerrainEntity::invalidateMapImages );
@@ -71,3 +71,8 @@ QString QgsTerrainGenerator::typeToString( QgsTerrainGenerator::Type type )
}
return QString();
}

bool QgsTerrainGenerator::isValid() const
{
return mIsValid;
}
@@ -99,9 +99,14 @@ class _3D_EXPORT QgsTerrainGenerator : public QgsChunkLoaderFactory
//! Returns CRS of the terrain
QgsCoordinateReferenceSystem crs() const { return mTerrainTilingScheme.crs(); }

//! Returns whether the terrain generator is valid
bool isValid() const;

protected:
QgsTilingScheme mTerrainTilingScheme; //!< Tiling scheme of the terrain
QgsTerrainEntity *mTerrain = nullptr;

bool mIsValid = true;
};


0 comments on commit 3b86c51

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