Browse Source

Update Buffer2D to allow disposal testing.

pull/2353/head
James Jackson-South 3 years ago
parent
commit
1a9db45a85
  1. 8
      src/ImageSharp/Memory/Buffer2D{T}.cs
  2. 8
      tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs

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

@ -55,6 +55,8 @@ public sealed class Buffer2D<T> : IDisposable
/// </remarks>
internal MemoryGroup<T> FastMemoryGroup { get; private set; }
internal bool IsDisposed { get; private set; }
/// <summary>
/// Gets a reference to the element at the specified position.
/// </summary>
@ -79,7 +81,11 @@ public sealed class Buffer2D<T> : IDisposable
/// <summary>
/// Disposes the <see cref="Buffer2D{T}"/> instance
/// </summary>
public void Dispose() => this.FastMemoryGroup.Dispose();
public void Dispose()
{
this.FastMemoryGroup.Dispose();
this.IsDisposed = true;
}
/// <summary>
/// Gets a <see cref="Span{T}"/> to the row 'y' beginning from the pixel at the first pixel on that row.

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

@ -182,12 +182,12 @@ public abstract partial class ImageFrameCollectionTests
new[] { imageFrame1, imageFrame2 });
IPixelSource<Rgba32>[] framesSnapShot = collection.OfType<IPixelSource<Rgba32>>().ToArray();
Assert.All(framesSnapShot, f => Assert.False(f.PixelBuffer.IsDisposed));
collection.Dispose();
Assert.All(
framesSnapShot,
f => // The pixel source of the frame is null after its been disposed.
Assert.Null(f.PixelBuffer));
Assert.All(framesSnapShot, f => Assert.True(f.PixelBuffer.IsDisposed));
}
[Theory]

Loading…
Cancel
Save