Skip to content

Commit aeeb5d9

Browse files
committedOct 28, 2016
Fix crash when loading WCS layers (fixes #15595)
The problem is that some providers would still issue network requests in prepareJobs() - this should be ideally avoided, because it is run in main thread - all the work should be deferred to be done in worker thread. (cherry picked from commit 08f4a0f)
1 parent 59d1d70 commit aeeb5d9

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed
 

‎src/core/qgsmaprenderercustompainterjob.cpp

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

8686
mLayerJobs = prepareJobs( mPainter, mLabelingEngineV2 );
87-
// prepareJobs calls mapLayer->createMapRenderer may involve cloning a RasterDataProvider,
88-
// whose constructor may need to download some data (i.e. WMS, AMS) and doing so runs a
89-
// QEventLoop waiting for the network request to complete. If unluckily someone calls
90-
// mapCanvas->refresh() while this is happening, QgsMapRendererCustomPainterJob::cancel is
91-
// called, deleting the QgsMapRendererCustomPainterJob while this function is running.
92-
// Hence we need to check whether the job is still active before proceeding
93-
if ( !isActive() )
94-
return;
9587

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

‎src/core/qgsmaprendererparalleljob.cpp

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

6464
mLayerJobs = prepareJobs( nullptr, mLabelingEngineV2 );
65-
// prepareJobs calls mapLayer->createMapRenderer may involve cloning a RasterDataProvider,
66-
// whose constructor may need to download some data (i.e. WMS, AMS) and doing so runs a
67-
// QEventLoop waiting for the network request to complete. If unluckily someone calls
68-
// mapCanvas->refresh() while this is happening, QgsMapRendererCustomPainterJob::cancel is
69-
// called, deleting the QgsMapRendererCustomPainterJob while this function is running.
70-
// Hence we need to check whether the job is still active before proceeding
71-
if ( !isActive() )
72-
return;
7365

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

‎src/gui/qgsmapcanvas.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,6 @@ void QgsMapCanvas::refreshMap()
575575

576576
stopRendering(); // if any...
577577

578-
// from now on we can accept refresh requests again
579-
mRefreshScheduled = false;
580-
581578
//build the expression context
582579
QgsExpressionContext expressionContext;
583580
expressionContext << QgsExpressionContextUtils::globalScope()
@@ -610,6 +607,14 @@ void QgsMapCanvas::refreshMap()
610607

611608
mJob->start();
612609

610+
// from now on we can accept refresh requests again
611+
// this must be reset only after the job has been started, because
612+
// some providers (yes, it's you WCS and AMS!) during preparation
613+
// do network requests and start an internal event loop, which may
614+
// end up calling refresh() and would schedule another refresh,
615+
// deleting the one we have just started.
616+
mRefreshScheduled = false;
617+
613618
mMapUpdateTimer.start();
614619

615620
emit renderStarting();

0 commit comments

Comments
 (0)
Please sign in to comment.