Skip to content

Commit 1a9db45

Browse files
Update Buffer2D to allow disposal testing.
1 parent a04526f commit 1a9db45

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/ImageSharp/Memory/Buffer2D{T}.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ internal Buffer2D(MemoryGroup<T> memoryGroup, int width, int height)
5555
/// </remarks>
5656
internal MemoryGroup<T> FastMemoryGroup { get; private set; }
5757

58+
internal bool IsDisposed { get; private set; }
59+
5860
/// <summary>
5961
/// Gets a reference to the element at the specified position.
6062
/// </summary>
@@ -79,7 +81,11 @@ internal Buffer2D(MemoryGroup<T> memoryGroup, int width, int height)
7981
/// <summary>
8082
/// Disposes the <see cref="Buffer2D{T}"/> instance
8183
/// </summary>
82-
public void Dispose() => this.FastMemoryGroup.Dispose();
84+
public void Dispose()
85+
{
86+
this.FastMemoryGroup.Dispose();
87+
this.IsDisposed = true;
88+
}
8389

8490
/// <summary>
8591
/// Gets a <see cref="Span{T}"/> to the row 'y' beginning from the pixel at the first pixel on that row.

tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ public void Dispose_DisposesAllInnerFrames()
182182
new[] { imageFrame1, imageFrame2 });
183183

184184
IPixelSource<Rgba32>[] framesSnapShot = collection.OfType<IPixelSource<Rgba32>>().ToArray();
185+
186+
Assert.All(framesSnapShot, f => Assert.False(f.PixelBuffer.IsDisposed));
187+
185188
collection.Dispose();
186189

187-
Assert.All(
188-
framesSnapShot,
189-
f => // The pixel source of the frame is null after its been disposed.
190-
Assert.Null(f.PixelBuffer));
190+
Assert.All(framesSnapShot, f => Assert.True(f.PixelBuffer.IsDisposed));
191191
}
192192

193193
[Theory]

0 commit comments

Comments
 (0)