Skip to content

Commit

Permalink
[3d] Fix a crash when restoring a project with bad layer ref (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jan 4, 2018
1 parent d6e43ef commit c9dba99
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/3d/qgs3dmapscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "qgsterrainentity_p.h"
#include "qgsterraingenerator.h"
#include "qgsvectorlayer.h"
#include "qgsvectorlayer3drenderer.h"


Qgs3DMapScene::Qgs3DMapScene( const Qgs3DMapSettings &map, Qt3DExtras::QForwardRenderer *defaultFrameGraph, Qt3DRender::QRenderSettings *renderSettings, Qt3DRender::QCamera *camera, const QRect &viewportRect, Qt3DCore::QNode *parent )
Expand Down Expand Up @@ -376,9 +377,22 @@ void Qgs3DMapScene::addLayerEntity( QgsMapLayer *layer )
QgsAbstract3DRenderer *renderer = layer->renderer3D();
if ( renderer )
{
// Fix vector layer's renderer to make sure the renderer is pointing to its layer.
// It has happened before that renderer pointed to a different layer (probably after copying a style).
// This is a bit of a hack and it should be handled in QgsMapLayer::setRenderer3D() but in qgis_core
// the vector layer 3D renderer class is not available. Maybe we need an intermediate map layer 3D renderer
// class in qgis_core that can be used to handle this case nicely.
if ( layer->type() == QgsMapLayer::VectorLayer && renderer->type() == "vector" )
{
static_cast<QgsVectorLayer3DRenderer *>( renderer )->setLayer( static_cast<QgsVectorLayer *>( layer ) );
}

Qt3DCore::QEntity *newEntity = renderer->createEntity( mMap );
newEntity->setParent( this );
mLayerEntities.insert( layer, newEntity );
if ( newEntity )
{
newEntity->setParent( this );
mLayerEntities.insert( layer, newEntity );
}
}

connect( layer, &QgsMapLayer::renderer3DChanged, this, &Qgs3DMapScene::onLayerRenderer3DChanged );
Expand Down

0 comments on commit c9dba99

Please sign in to comment.