Skip to content

Commit

Permalink
Remove ArrayPool usage for now to avoid BufferUnderflow (#1961)
Browse files Browse the repository at this point in the history
Co-authored-by: Shaun Lawrence <[email protected]>
  • Loading branch information
bijington and bijington committed Jun 20, 2024
1 parent e57d9cc commit 742fe87
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/CommunityToolkit.Maui.Camera/CameraManager.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,21 +273,21 @@ public override void OnCaptureSuccess(IImageProxy image)
{
base.OnCaptureSuccess(image);
var img = image.Image;

if (img is null)
{
return;
}

var buffer = GetFirstPlane(img.GetPlanes())?.Buffer;

if (buffer is null)
{
image.Close();
return;
}

var imgData = ArrayPool<byte>.Shared.Rent(buffer.Capacity());
var imgData = new byte[buffer.Remaining()];
try
{
buffer.Get(imgData);
Expand All @@ -297,7 +297,6 @@ public override void OnCaptureSuccess(IImageProxy image)
finally
{
image.Close();
ArrayPool<byte>.Shared.Return(imgData);
}

static Plane? GetFirstPlane(Plane[]? planes)
Expand Down

0 comments on commit 742fe87

Please sign in to comment.