@@ -699,6 +699,27 @@ bool QgsSymbolV2::hasDataDefinedProperties() const
699
699
return false ;
700
700
}
701
701
702
+ // /@cond PRIVATE
703
+
704
+ /* *
705
+ * RAII class to pop scope from an expression context on destruction
706
+ */
707
+ class ExpressionContextScopePopper
708
+ {
709
+ public:
710
+
711
+ ExpressionContextScopePopper () = default ;
712
+
713
+ ~ExpressionContextScopePopper ()
714
+ {
715
+ if ( context )
716
+ context->popScope ();
717
+ }
718
+
719
+ QgsExpressionContext *context = nullptr ;
720
+ };
721
+ // /@endcond PRIVATE
722
+
702
723
void QgsSymbolV2::renderFeature ( const QgsFeature& feature, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker, int currentVertexMarkerType, int currentVertexMarkerSize )
703
724
{
704
725
const QgsGeometry* geom = feature.constGeometry ();
@@ -728,9 +749,17 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
728
749
mSymbolRenderContext ->setGeometryPartCount ( segmentizedGeometry->geometry ()->partCount () );
729
750
mSymbolRenderContext ->setGeometryPartNum ( 1 );
730
751
752
+ ExpressionContextScopePopper scopePopper;
731
753
if ( mSymbolRenderContext ->expressionContextScope () )
732
754
{
755
+ // this is somewhat nasty - by appending this scope here it's now owned
756
+ // by both mSymbolRenderContext AND context.expressionContext()
757
+ // the RAII scopePopper is required to make sure it always has ownership transferred back
758
+ // from context.expressionContext(), even if exceptions of other early exits occur in this
759
+ // function
733
760
context.expressionContext ().appendScope ( mSymbolRenderContext ->expressionContextScope () );
761
+ scopePopper.context = &context.expressionContext ();
762
+
734
763
QgsExpressionContextUtils::updateSymbolScope ( this , mSymbolRenderContext ->expressionContextScope () );
735
764
mSymbolRenderContext ->expressionContextScope ()->addVariable ( QgsExpressionContextScope::StaticVariable ( QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT, mSymbolRenderContext ->geometryPartCount (), true ) );
736
765
mSymbolRenderContext ->expressionContextScope ()->addVariable ( QgsExpressionContextScope::StaticVariable ( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, 1 , true ) );
@@ -1011,9 +1040,6 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
1011
1040
{
1012
1041
delete segmentizedGeometry;
1013
1042
}
1014
-
1015
- if ( mSymbolRenderContext ->expressionContextScope () )
1016
- context.expressionContext ().popScope ();
1017
1043
}
1018
1044
1019
1045
QgsSymbolV2RenderContext* QgsSymbolV2::symbolRenderContext ()
0 commit comments