Skip to content

Commit ca5041b

Browse files
uclarosnyalldawson
authored andcommittedOct 19, 2023
check if Qgs3DMapScene has been created before accessing
1 parent 689a935 commit ca5041b

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed
 

‎src/app/3d/qgs3dmapcanvas.cpp‎

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,38 +149,47 @@ QgsCameraController *Qgs3DMapCanvas::cameraController()
149149

150150
void Qgs3DMapCanvas::resetView()
151151
{
152+
if ( !mScene )
153+
return;
154+
152155
mScene->viewZoomFull();
153156
}
154157

155158
void Qgs3DMapCanvas::setViewFromTop( const QgsPointXY &center, float distance, float rotation )
156159
{
160+
if ( !mScene )
161+
return;
162+
157163
const float worldX = center.x() - mMap->origin().x();
158164
const float worldY = center.y() - mMap->origin().y();
159165
mScene->cameraController()->setViewFromTop( worldX, -worldY, distance, rotation );
160166
}
161167

162168
void Qgs3DMapCanvas::saveAsImage( const QString &fileName, const QString &fileFormat )
163169
{
164-
if ( !fileName.isEmpty() )
170+
if ( !mScene || fileName.isEmpty() )
171+
return;
172+
173+
mCaptureFileName = fileName;
174+
mCaptureFileFormat = fileFormat;
175+
mEngine->setRenderCaptureEnabled( true );
176+
// Setup a frame action that is used to wait until next frame
177+
Qt3DLogic::QFrameAction *screenCaptureFrameAction = new Qt3DLogic::QFrameAction;
178+
mScene->addComponent( screenCaptureFrameAction );
179+
// Wait to have the render capture enabled in the next frame
180+
connect( screenCaptureFrameAction, &Qt3DLogic::QFrameAction::triggered, this, [ = ]( float )
165181
{
166-
mCaptureFileName = fileName;
167-
mCaptureFileFormat = fileFormat;
168-
mEngine->setRenderCaptureEnabled( true );
169-
// Setup a frame action that is used to wait until next frame
170-
Qt3DLogic::QFrameAction *screenCaptureFrameAction = new Qt3DLogic::QFrameAction;
171-
mScene->addComponent( screenCaptureFrameAction );
172-
// Wait to have the render capture enabled in the next frame
173-
connect( screenCaptureFrameAction, &Qt3DLogic::QFrameAction::triggered, this, [ = ]( float )
174-
{
175-
mEngine->requestCaptureImage();
176-
mScene->removeComponent( screenCaptureFrameAction );
177-
screenCaptureFrameAction->deleteLater();
178-
} );
179-
}
182+
mEngine->requestCaptureImage();
183+
mScene->removeComponent( screenCaptureFrameAction );
184+
screenCaptureFrameAction->deleteLater();
185+
} );
180186
}
181187

182188
void Qgs3DMapCanvas::captureDepthBuffer()
183189
{
190+
if ( !mScene )
191+
return;
192+
184193
// Setup a frame action that is used to wait until next frame
185194
Qt3DLogic::QFrameAction *screenCaptureFrameAction = new Qt3DLogic::QFrameAction;
186195
mScene->addComponent( screenCaptureFrameAction );
@@ -195,6 +204,9 @@ void Qgs3DMapCanvas::captureDepthBuffer()
195204

196205
void Qgs3DMapCanvas::setMapTool( Qgs3DMapTool *tool )
197206
{
207+
if ( !mScene )
208+
return;
209+
198210
if ( tool == mMapTool )
199211
return;
200212

@@ -281,6 +293,9 @@ void Qgs3DMapCanvas::setTemporalController( QgsTemporalController *temporalContr
281293

282294
void Qgs3DMapCanvas::updateTemporalRange( const QgsDateTimeRange &temporalrange )
283295
{
296+
if ( !mScene )
297+
return;
298+
284299
mMap->setTemporalRange( temporalrange );
285300
mScene->updateTemporal();
286301
}
@@ -297,10 +312,13 @@ void Qgs3DMapCanvas::onNavigationModeChanged( Qgis::NavigationMode mode )
297312

298313
void Qgs3DMapCanvas::setViewFrom2DExtent( const QgsRectangle &extent )
299314
{
315+
if ( !mScene )
316+
return;
317+
300318
mScene->setViewFrom2DExtent( extent );
301319
}
302320

303321
QVector<QgsPointXY> Qgs3DMapCanvas::viewFrustum2DExtent()
304322
{
305-
return mScene->viewFrustum2DExtent();
323+
return mScene ? mScene->viewFrustum2DExtent() : QVector<QgsPointXY>();
306324
}

0 commit comments

Comments
 (0)
Please sign in to comment.