SkiaSharp: [BUG] 2.84.0-preview.4: SKCodec.Create - Value cannot be null. Parameter name: buffer
Description
Exception “Value cannot be null. Parameter name: buffer” on SKCodec.Create
- stack:
SkiaSharp.SKManagedStream.OnReadManagedStream(IntPtr buffer, IntPtr size)
SkiaSharp.SKAbstractManagedStream.ReadInternal(IntPtr s, Void* context, Void* buffer, IntPtr size)
SkiaSharp.SKCodec.Create(SKStream stream, SKCodecResult& result)
This only happens on a few images - attached one.
Code
// inStream is a filestream
using var imgStream = new SKManagedStream(inStream);
using var codec = SKCodec.Create(imgStream, out SKCodecResult result);
Basic Information
Version with issue: 2.84.0-preview.4 Last known good version: 2.84.0-preview.1 IDE: Visual Studio 2019 Platform Target Frameworks: .NETFramework 4.8
Image File Sample
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 14
- Comments: 23 (3 by maintainers)
Links to this issue
Commits related to this issue
- Use previous skia sharp version due to issue https://github.com/mono/SkiaSharp/issues/1551 — committed to epsmae/photo-booth-dot-net by deleted user 3 years ago
- https://github.com/mono/SkiaSharp/issues/1551 — committed to Djohnnie/Photo-Carousel by Djohnnie 3 years ago
- https://github.com/mono/SkiaSharp/issues/1551 — committed to Djohnnie/Photo-Carousel by Djohnnie 3 years ago
- https://github.com/mono/SkiaSharp/issues/1551 — committed to Djohnnie/Photo-Carousel by Djohnnie 3 years ago
- Workaround for mono/SkiaSharp#1551 Fixes #7773 — committed to Fusion86/Avalonia by Fusion86 2 years ago
- Work around mono/SkiaSharp/#1551 Use the workaround from https://github.com/mono/SkiaSharp/issues/1551#issuecomment-756685252 to load bitmaps. Fixes #7773 — committed to AvaloniaUI/Avalonia by grokys 2 years ago
I did this as a workaround - go through
SKData
instead of creating the codec from a stream:rolled back to previous version 2.80.2
We are getting “Value cannot be null” error on Android while creating bitmap.
SKBitmap bitMap = SKBitmap.Decode(new MemoryStream(mediaFileBytearray));
Hi folks. Sorry it took forever to fix this - especially since it was so simple and totally my fault. I will try get a package out ASAP after this merges: https://github.com/mono/SkiaSharp/pull/2265
I had the same issue with this photo that I have zipped up that I got from google. I have another if needed as 2 of my 12 testing photos threw this error
Value cannot be null. Parameter name: buffer.
The fix was instead of doing this:Solution was this:
Any status on the core reasoning behind this? I am using Version=“2.88.0”
14b05c00-558d-40af-93aa-608a1a3441db.zip
I’ve got the same error after upgrading
SkiaSharp.NativeAssets.Linux
from v2.80.2 to v2.80.3. The crash occurs in production using Dockermcr.microsoft.com/dotnet/aspnet:5.0-alpine
as base image.I do not control the calls to Skia as I’m using a library that uses it (i.e. Aspose.Words), so I cannot try to proposed workaround. 😕
Could this be related to this PR #1510
Also ran into this on iOS and Android in Xamarin.Forms.
Doing
var bitmap = SKBitmap.Decode(stream)
(wherestream
is aMemoryStream
) and I get the following exception.Doing @BenjaminMichaelis’s suggestion above worked.
Thanks!!
@AndersMad, you’ve just saved my day! Thank you!