From 0eaba81c384fb615cbf72e1f64872befac315f8c Mon Sep 17 00:00:00 2001 From: Vincent Cloarec Date: Sat, 4 Apr 2020 06:56:38 -0400 Subject: [PATCH] [BUG][3D] fix 3D crash with measure line (#35412) * fix 3D crash with measure line * avoid non wanted windows opening of identify tool and measurment tool * adds guard avoid crashing when closing settings * spelling --- src/app/3d/qgs3dmaptoolidentify.cpp | 6 ++++++ src/app/3d/qgs3dmaptoolidentify.h | 2 ++ src/app/3d/qgs3dmaptoolmeasureline.cpp | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/src/app/3d/qgs3dmaptoolidentify.cpp b/src/app/3d/qgs3dmaptoolidentify.cpp index 8b65da9ca14..92c602bb2a6 100644 --- a/src/app/3d/qgs3dmaptoolidentify.cpp +++ b/src/app/3d/qgs3dmaptoolidentify.cpp @@ -87,6 +87,7 @@ void Qgs3DMapToolIdentify::activate() } mCanvas->scene()->registerPickHandler( mPickHandler.get() ); + mIsActive = true; } void Qgs3DMapToolIdentify::deactivate() @@ -97,6 +98,7 @@ void Qgs3DMapToolIdentify::deactivate() } mCanvas->scene()->unregisterPickHandler( mPickHandler.get() ); + mIsActive = false; } QCursor Qgs3DMapToolIdentify::cursor() const @@ -106,6 +108,8 @@ QCursor Qgs3DMapToolIdentify::cursor() const void Qgs3DMapToolIdentify::onMapSettingsChanged() { + if ( !mIsActive ) + return; connect( mCanvas->scene(), &Qgs3DMapScene::terrainEntityChanged, this, &Qgs3DMapToolIdentify::onTerrainEntityChanged ); } @@ -153,6 +157,8 @@ void Qgs3DMapToolIdentify::onTerrainPicked( Qt3DRender::QPickEvent *event ) void Qgs3DMapToolIdentify::onTerrainEntityChanged() { + if ( !mIsActive ) + return; // no need to disconnect from the previous entity: it has been destroyed // start listening to the new terrain entity if ( QgsTerrainEntity *terrainEntity = mCanvas->scene()->terrainEntity() ) diff --git a/src/app/3d/qgs3dmaptoolidentify.h b/src/app/3d/qgs3dmaptoolidentify.h index 0b2b2aaf4bc..58a9b8be000 100644 --- a/src/app/3d/qgs3dmaptoolidentify.h +++ b/src/app/3d/qgs3dmaptoolidentify.h @@ -53,6 +53,8 @@ class Qgs3DMapToolIdentify : public Qgs3DMapTool private: std::unique_ptr mPickHandler; + bool mIsActive = false; + friend class Qgs3DMapToolIdentifyPickHandler; }; diff --git a/src/app/3d/qgs3dmaptoolmeasureline.cpp b/src/app/3d/qgs3dmaptoolmeasureline.cpp index ed550c1797a..5a84dc26159 100644 --- a/src/app/3d/qgs3dmaptoolmeasureline.cpp +++ b/src/app/3d/qgs3dmaptoolmeasureline.cpp @@ -124,6 +124,8 @@ QCursor Qgs3DMapToolMeasureLine::cursor() const void Qgs3DMapToolMeasureLine::onMapSettingsChanged() { + if ( !mIsAlreadyActivated ) + return; connect( mCanvas->scene(), &Qgs3DMapScene::terrainEntityChanged, this, &Qgs3DMapToolMeasureLine::onTerrainEntityChanged ); // Update scale if the terrain vertical scale changed @@ -137,6 +139,8 @@ void Qgs3DMapToolMeasureLine::onTerrainPicked( Qt3DRender::QPickEvent *event ) void Qgs3DMapToolMeasureLine::onTerrainEntityChanged() { + if ( !mIsAlreadyActivated ) + return; // no need to disconnect from the previous entity: it has been destroyed // start listening to the new terrain entity if ( QgsTerrainEntity *terrainEntity = mCanvas->scene()->terrainEntity() ) @@ -175,6 +179,8 @@ void Qgs3DMapToolMeasureLine::handleClick( Qt3DRender::QPickEvent *event, const void Qgs3DMapToolMeasureLine::updateMeasurementLayer() { + if ( !mMeasurementLayer ) + return; double verticalScale = canvas()->map()->terrainVerticalScale(); QgsLineString *line; if ( verticalScale != 1.0 ) @@ -205,6 +211,8 @@ void Qgs3DMapToolMeasureLine::updateMeasurementLayer() void Qgs3DMapToolMeasureLine::updateSettings() { + if ( !mMeasurementLayer ) + return; // Line style QgsLine3DSymbol *lineSymbol = new QgsLine3DSymbol; lineSymbol->setRenderAsSimpleLines( true );