Skip to content

Commit 996e2e1

Browse files
committed
Merge pull request #3120 from manisandro/rendering_crash
Guard against possible crash by using destroyed QgsMapRendererCustomPainterJob
2 parents 73ab289 + 759dd9d commit 996e2e1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/core/qgsmaprenderercustompainterjob.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ void QgsMapRendererCustomPainterJob::start()
9797
}
9898

9999
mLayerJobs = prepareJobs( mPainter, mLabelingEngine, mLabelingEngineV2 );
100+
// prepareJobs calls mapLayer->createMapRenderer may involve cloning a RasterDataProvider,
101+
// whose constructor may need to download some data (i.e. WMS, AMS) and doing so runs a
102+
// QEventLoop waiting for the network request to complete. If unluckily someone calls
103+
// mapCanvas->refresh() while this is happening, QgsMapRendererCustomPainterJob::cancel is
104+
// called, deleting the QgsMapRendererCustomPainterJob while this function is running.
105+
// Hence we need to check whether the job is still active before proceeding
106+
if ( !isActive() )
107+
return;
100108

101109
QgsDebugMsg( "Rendering prepared in (seconds): " + QString( "%1" ).arg( prepareTime.elapsed() / 1000.0 ) );
102110

src/core/qgsmaprendererparalleljob.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ void QgsMapRendererParallelJob::start()
7575
}
7676

7777
mLayerJobs = prepareJobs( nullptr, mLabelingEngine, mLabelingEngineV2 );
78+
// prepareJobs calls mapLayer->createMapRenderer may involve cloning a RasterDataProvider,
79+
// whose constructor may need to download some data (i.e. WMS, AMS) and doing so runs a
80+
// QEventLoop waiting for the network request to complete. If unluckily someone calls
81+
// mapCanvas->refresh() while this is happening, QgsMapRendererCustomPainterJob::cancel is
82+
// called, deleting the QgsMapRendererCustomPainterJob while this function is running.
83+
// Hence we need to check whether the job is still active before proceeding
84+
if ( !isActive() )
85+
return;
7886

7987
QgsDebugMsg( QString( "QThreadPool max thread count is %1" ).arg( QThreadPool::globalInstance()->maxThreadCount() ) );
8088

0 commit comments

Comments
 (0)