Skip to content

Commit cd8ab68

Browse files
committedJun 7, 2018
fix crash when highlighting invisible features
(3.x apparently not affected)
1 parent 268b9ac commit cd8ab68

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed
 

‎src/core/symbology-ng/qgssymbolv2.cpp

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -753,23 +753,26 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
753753
deleteSegmentizedGeometry = true;
754754
}
755755

756-
mSymbolRenderContext->setGeometryPartCount( segmentizedGeometry->geometry()->partCount() );
757-
mSymbolRenderContext->setGeometryPartNum( 1 );
758-
759756
ExpressionContextScopePopper scopePopper;
760-
if ( mSymbolRenderContext->expressionContextScope() )
757+
if ( mSymbolRenderContext )
761758
{
762-
// this is somewhat nasty - by appending this scope here it's now owned
763-
// by both mSymbolRenderContext AND context.expressionContext()
764-
// the RAII scopePopper is required to make sure it always has ownership transferred back
765-
// from context.expressionContext(), even if exceptions of other early exits occur in this
766-
// function
767-
context.expressionContext().appendScope( mSymbolRenderContext->expressionContextScope() );
768-
scopePopper.context = &context.expressionContext();
759+
mSymbolRenderContext->setGeometryPartCount( segmentizedGeometry->geometry()->partCount() );
760+
mSymbolRenderContext->setGeometryPartNum( 1 );
769761

770-
QgsExpressionContextUtils::updateSymbolScope( this, mSymbolRenderContext->expressionContextScope() );
771-
mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT, mSymbolRenderContext->geometryPartCount(), true ) );
772-
mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, 1, true ) );
762+
if ( mSymbolRenderContext->expressionContextScope() )
763+
{
764+
// this is somewhat nasty - by appending this scope here it's now owned
765+
// by both mSymbolRenderContext AND context.expressionContext()
766+
// the RAII scopePopper is required to make sure it always has ownership transferred back
767+
// from context.expressionContext(), even if exceptions of other early exits occur in this
768+
// function
769+
context.expressionContext().appendScope( mSymbolRenderContext->expressionContextScope() );
770+
scopePopper.context = &context.expressionContext();
771+
772+
QgsExpressionContextUtils::updateSymbolScope( this, mSymbolRenderContext->expressionContextScope() );
773+
mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT, mSymbolRenderContext->geometryPartCount(), true ) );
774+
mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, 1, true ) );
775+
}
773776
}
774777

775778
// Collection of markers to paint, only used for no curve types.
@@ -866,8 +869,11 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
866869

867870
for ( int i = 0; i < mp->numGeometries(); ++i )
868871
{
869-
mSymbolRenderContext->setGeometryPartNum( i + 1 );
870-
mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1, true ) );
872+
if ( mSymbolRenderContext )
873+
{
874+
mSymbolRenderContext->setGeometryPartNum( i + 1 );
875+
mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1, true ) );
876+
}
871877

872878
const QgsPointV2* point = static_cast< const QgsPointV2* >( mp->geometryN( i ) );
873879
_getPoint( pt, context, point );
@@ -902,8 +908,11 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
902908

903909
for ( unsigned int i = 0; i < num && wkbPtr; ++i )
904910
{
905-
mSymbolRenderContext->setGeometryPartNum( i + 1 );
906-
mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1, true ) );
911+
if ( mSymbolRenderContext )
912+
{
913+
mSymbolRenderContext->setGeometryPartNum( i + 1 );
914+
mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1, true ) );
915+
}
907916

908917
if ( geomCollection )
909918
{
@@ -952,8 +961,11 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
952961

953962
for ( unsigned int i = 0; i < num && wkbPtr; ++i )
954963
{
955-
mSymbolRenderContext->setGeometryPartNum( i + 1 );
956-
mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1, true ) );
964+
if ( mSymbolRenderContext )
965+
{
966+
mSymbolRenderContext->setGeometryPartNum( i + 1 );
967+
mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1, true ) );
968+
}
957969

958970
if ( geomCollection )
959971
{

0 commit comments

Comments
 (0)
Please sign in to comment.