Skip to content

Commit 08f4a0f

Browse files
committedOct 5, 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.
1 parent ed8c02f commit 08f4a0f

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
@@ -98,14 +98,6 @@ void QgsMapRendererCustomPainterJob::start()
9898
}
9999

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

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

‎src/core/qgsmaprendererparalleljob.cpp

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

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

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

‎src/gui/qgsmapcanvas.cpp

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

707707
stopRendering(); // if any...
708708

709-
// from now on we can accept refresh requests again
710-
mRefreshScheduled = false;
711-
712709
//build the expression context
713710
QgsExpressionContext expressionContext;
714711
expressionContext << QgsExpressionContextUtils::globalScope()
@@ -741,6 +738,14 @@ void QgsMapCanvas::refreshMap()
741738

742739
mJob->start();
743740

741+
// from now on we can accept refresh requests again
742+
// this must be reset only after the job has been started, because
743+
// some providers (yes, it's you WCS and AMS!) during preparation
744+
// do network requests and start an internal event loop, which may
745+
// end up calling refresh() and would schedule another refresh,
746+
// deleting the one we have just started.
747+
mRefreshScheduled = false;
748+
744749
mMapUpdateTimer.start();
745750

746751
emit renderStarting();

0 commit comments

Comments
 (0)
Please sign in to comment.