From e4f29f447d37ffcf2f8d7e98446784337e56149d Mon Sep 17 00:00:00 2001 From: Roman Kalachik Date: Thu, 29 Feb 2024 16:51:49 +0300 Subject: [PATCH] refactoring --- .../SvgCustomDrawOperation.cs | 35 ++++++++++--------- src/Svg.Skia/SKSvg.Model.cs | 7 ++-- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/Avalonia.Svg.Skia/SvgCustomDrawOperation.cs b/src/Avalonia.Svg.Skia/SvgCustomDrawOperation.cs index 2223b057..2774d78f 100644 --- a/src/Avalonia.Svg.Skia/SvgCustomDrawOperation.cs +++ b/src/Avalonia.Svg.Skia/SvgCustomDrawOperation.cs @@ -28,27 +28,28 @@ public void Dispose() public void Render(ImmediateDrawingContext context) { + if (_svg == null) + return; + + + var leaseFeature = context.TryGetFeature(); + if (leaseFeature is null) + { + return; + } + using var lease = leaseFeature.Lease(); + var canvas = lease?.SkCanvas; + if (canvas is null) + { + return; + } lock (_svg.Locker) { - if (_svg?.Picture is null) - { - return; - } - - var leaseFeature = context.TryGetFeature(); - if (leaseFeature is null) - { + var picture = _svg.Picture; + if (picture is null) return; - } - using var lease = leaseFeature.Lease(); - var canvas = lease?.SkCanvas; - if (canvas is null) - { - return; - } - canvas.Save(); - canvas.DrawPicture(_svg.Picture); + canvas.DrawPicture(picture); canvas.Restore(); } } diff --git a/src/Svg.Skia/SKSvg.Model.cs b/src/Svg.Skia/SKSvg.Model.cs index 31088ef2..0cdce7c5 100644 --- a/src/Svg.Skia/SKSvg.Model.cs +++ b/src/Svg.Skia/SKSvg.Model.cs @@ -253,8 +253,11 @@ private void Reset() { Model = null; Drawable = null; - Picture?.Dispose(); - Picture = null; + lock (Locker) + { + Picture?.Dispose(); + Picture = null; + } } public void Dispose()