Skip to content

Commit

Permalink
Fix crash when loading WCS layers (fixes #15595)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
wonder-sk committed Oct 28, 2016
1 parent 59d1d70 commit aeeb5d9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
8 changes: 0 additions & 8 deletions src/core/qgsmaprenderercustompainterjob.cpp
Expand Up @@ -84,14 +84,6 @@ void QgsMapRendererCustomPainterJob::start()
}

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

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

Expand Down
8 changes: 0 additions & 8 deletions src/core/qgsmaprendererparalleljob.cpp
Expand Up @@ -62,14 +62,6 @@ void QgsMapRendererParallelJob::start()
}

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

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

Expand Down
11 changes: 8 additions & 3 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -575,9 +575,6 @@ void QgsMapCanvas::refreshMap()

stopRendering(); // if any...

// from now on we can accept refresh requests again
mRefreshScheduled = false;

//build the expression context
QgsExpressionContext expressionContext;
expressionContext << QgsExpressionContextUtils::globalScope()
Expand Down Expand Up @@ -610,6 +607,14 @@ void QgsMapCanvas::refreshMap()

mJob->start();

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

mMapUpdateTimer.start();

emit renderStarting();
Expand Down

0 comments on commit aeeb5d9

Please sign in to comment.