@@ -184,7 +184,7 @@ protected override void ProcessOperations(IReadOnlyList<IGraphicsStateOperation>
184184 {
185185 _token . ThrowIfCancellationRequested ( ) ;
186186 }
187-
187+
188188 operations [ i ] . Run ( this ) ;
189189 }
190190 }
@@ -195,7 +195,7 @@ public override void PopState()
195195 // composited into the still-open offscreen buffer. DstIn keeps only the parts of
196196 // the layer where the mask has alpha; the LumaColor filter converts the source
197197 // colour to luminosity-as-alpha for /Luminosity-subtype masks.
198- var maskImage = _pendingMasks . Pop ( ) ;
198+ var maskImage = _pendingMasks . Count > 0 ? _pendingMasks . Pop ( ) : null ;
199199 if ( maskImage is not null )
200200 {
201201 _canvas . Save ( ) ;
@@ -204,11 +204,9 @@ public override void PopState()
204204 // covering the same logical bounds as the layer).
205205 _canvas . SetMatrix ( SKMatrix . Identity ) ;
206206
207- using var maskPaint = new SKPaint
208- {
209- BlendMode = SKBlendMode . DstIn ,
210- ColorFilter = SKColorFilter . CreateLumaColor ( )
211- } ;
207+ using var maskPaint = new SKPaint ( ) ;
208+ maskPaint . BlendMode = SKBlendMode . DstIn ;
209+ maskPaint . ColorFilter = SKColorFilter . CreateLumaColor ( ) ;
212210
213211 _canvas . DrawImage ( maskImage , SKRect . Create ( 0 , 0 , _width , _height ) , maskPaint ) ;
214212 _canvas . Restore ( ) ;
@@ -219,7 +217,7 @@ public override void PopState()
219217 _canvas . Restore ( ) ;
220218
221219 // Dispose layer paint if one was used for this state
222- var layerPaint = _transparencyLayerPaints . Pop ( ) ;
220+ var layerPaint = _transparencyLayerPaints . Count > 0 ? _transparencyLayerPaints . Pop ( ) : null ;
223221 layerPaint ? . Dispose ( ) ;
224222
225223 EndPath ( ) ;
0 commit comments