Skip to content
Permalink
Browse files

Add an assert to protect multiple calls to QgsSymbolV2::startRender()

while rendering has already been started for a particular symbol instance

Relates to a random but frequent crash which occurs when using the
categorised symbol renderer - tracked down to a race condition
in which multiple concurrent calls to startRender() are performed
on a single symbol instance.
  • Loading branch information
nyalldawson committed Jul 10, 2017
1 parent e6dc103 commit 348088e773a5c41b0bd18e32905c79c8e3d68ee7
Showing with 10 additions and 1 deletion.
  1. +7 −1 src/core/symbology-ng/qgssymbolv2.cpp
  2. +3 −0 src/core/symbology-ng/qgssymbolv2.h
@@ -89,9 +89,9 @@ QgsSymbolV2::QgsSymbolV2( SymbolType type, const QgsSymbolLayerV2List& layers )
, mRenderHints( 0 )
, mClipFeaturesToExtent( true )
, mLayer( nullptr )
, mStarted( false )
, mSymbolRenderContext( nullptr )
{

// check they're all correct symbol layers
for ( int i = 0; i < mLayers.count(); i++ )
{
@@ -444,6 +444,9 @@ bool QgsSymbolV2::changeSymbolLayer( int index, QgsSymbolLayerV2* layer )

void QgsSymbolV2::startRender( QgsRenderContext& context, const QgsFields* fields )
{
Q_ASSERT_X( !mStarted, "startRender", "Rendering has already been started for this symbol instance!" );

mStarted = true;
delete mSymbolRenderContext;
mSymbolRenderContext = new QgsSymbolV2RenderContext( context, outputUnit(), mAlpha, false, mRenderHints, nullptr, fields, mapUnitScale() );

@@ -459,6 +462,9 @@ void QgsSymbolV2::startRender( QgsRenderContext& context, const QgsFields* field

void QgsSymbolV2::stopRender( QgsRenderContext& context )
{
Q_ASSERT_X( mStarted, "startRender", "startRender was not called for this symbol instance!" );
mStarted = false;

Q_UNUSED( context )
if ( mSymbolRenderContext )
{
@@ -335,6 +335,9 @@ class CORE_EXPORT QgsSymbolV2
const QgsVectorLayer* mLayer; //current vectorlayer

private:
//! True if render has already been started - guards against multiple calls to
//! startRender() (usually a result of not cloning a shared symbol instance before rendering).
bool mStarted;
//! Initialized in startRender, destroyed in stopRender
QgsSymbolV2RenderContext* mSymbolRenderContext;

0 comments on commit 348088e

Please sign in to comment.
You can’t perform that action at this time.