From 7771c833ce9487a00b380f5e4d32488d9c0697ed Mon Sep 17 00:00:00 2001 From: BorisTheBrave Date: Sat, 27 Apr 2019 23:27:04 +0100 Subject: [PATCH] ImageBrush shouldn't Dispose of the image it is using. (#883) Fixes #881 --- .../Processing/ImageBrush{TPixel}.cs | 1 - .../Drawing/FillImageBrushTests.cs | 36 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/ImageSharp.Tests/Drawing/FillImageBrushTests.cs diff --git a/src/ImageSharp.Drawing/Processing/ImageBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/ImageBrush{TPixel}.cs index 1ef4bb9ec9..cfb3b2ea4f 100644 --- a/src/ImageSharp.Drawing/Processing/ImageBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/ImageBrush{TPixel}.cs @@ -113,7 +113,6 @@ public ImageBrushApplicator(ImageFrame target, ImageFrame image, /// public override void Dispose() { - this.source.Dispose(); } /// diff --git a/tests/ImageSharp.Tests/Drawing/FillImageBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillImageBrushTests.cs new file mode 100644 index 0000000000..772f62d5cc --- /dev/null +++ b/tests/ImageSharp.Tests/Drawing/FillImageBrushTests.cs @@ -0,0 +1,36 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; +using SixLabors.Primitives; +using SixLabors.Shapes; + +using Xunit; + +// ReSharper disable InconsistentNaming + +namespace SixLabors.ImageSharp.Tests.Drawing +{ + [GroupOutput("Drawing")] + public class FillImageBrushTests + { + [Fact] + public void DoesNotDisposeImage() + { + using (var src = new Image(5, 5)) + { + var brush = new ImageBrush(src); + using (var dest = new Image(10, 10)) + { + dest.Mutate(c => c.Fill(brush, new Rectangle(0, 0, 10, 10))); + dest.Mutate(c => c.Fill(brush, new Rectangle(0, 0, 10, 10))); + } + } + } + } +} \ No newline at end of file