Skip to content

Commit

Permalink
Merge pull request #4830 from nyalldawson/fix_categorised_render_crash
Browse files Browse the repository at this point in the history
Fix categorised render crash
  • Loading branch information
nyalldawson committed Jul 11, 2017
2 parents ff5181c + 7db483d commit eec19de
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
11 changes: 0 additions & 11 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
Expand Up @@ -445,12 +445,6 @@ void QgsCategorizedSymbolRendererV2::startRender( QgsRenderContext& context, con
mTempSymbols[ cat.symbol()] = tempSymbol;
}
}

Q_FOREACH ( QgsSymbolV2 *symbol, mSymbolHash.values() )
{
symbol->startRender( context, &fields );
}

return;
}

Expand All @@ -461,11 +455,6 @@ void QgsCategorizedSymbolRendererV2::stopRender( QgsRenderContext& context )
cat.symbol()->stopRender( context );
}

Q_FOREACH ( QgsSymbolV2 *symbol, mSymbolHash.values() )
{
symbol->stopRender( context );
}

// cleanup mTempSymbols
QHash<QgsSymbolV2*, QgsSymbolV2*>::const_iterator it2 = mTempSymbols.constBegin();
for ( ; it2 != mTempSymbols.constEnd(); ++it2 )
Expand Down
8 changes: 7 additions & 1 deletion src/core/symbology-ng/qgssymbolv2.cpp
Expand Up @@ -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++ )
{
Expand Down Expand Up @@ -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() );

Expand All @@ -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 )
{
Expand Down
3 changes: 3 additions & 0 deletions src/core/symbology-ng/qgssymbolv2.h
Expand Up @@ -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;

Expand Down

0 comments on commit eec19de

Please sign in to comment.