Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitmap.DecodeToWidth() fails in 0.10.11, 0.10.12 and 0.10.13 #7773

Closed
stakira opened this issue Mar 9, 2022 · 5 comments · Fixed by #8601
Closed

Bitmap.DecodeToWidth() fails in 0.10.11, 0.10.12 and 0.10.13 #7773

stakira opened this issue Mar 9, 2022 · 5 comments · Fixed by #8601

Comments

@stakira
Copy link

stakira commented Mar 9, 2022

Describe the bug
Fails to load bitmap in 0.10.11, 0.10.12 and 0.10.13. Succeeds in 0.10.10 and earlier.

System.ArgumentNullException: Value cannot be null. (Parameter 'buffer')
   at SkiaSharp.SKManagedStream.OnReadManagedStream(IntPtr buffer, IntPtr size)
   at SkiaSharp.SKManagedStream.OnRead(IntPtr buffer, IntPtr size)
   at SkiaSharp.SKAbstractManagedStream.ReadInternal(IntPtr s, Void* context, Void* buffer, IntPtr size)
   at SkiaSharp.SkiaApi.sk_codec_get_pixels(IntPtr codec, SKImageInfoNative* info, Void* pixels, IntPtr rowBytes, SKCodecOptionsInternal* options)
   at SkiaSharp.SKCodec.GetPixels(SKImageInfo info, IntPtr pixels, Int32 rowBytes, SKCodecOptions options)
   at SkiaSharp.SKCodec.GetPixels(SKImageInfo info, IntPtr pixels)
   at SkiaSharp.SKBitmap.Decode(SKCodec codec, SKImageInfo bitmapInfo)
   at Avalonia.Skia.ImmutableBitmap..ctor(Stream stream, Int32 decodeSize, Boolean horizontal, BitmapInterpolationMode interpolationMode) in /_/src/Skia/Avalonia.Skia/ImmutableBitmap.cs:line 69
   at Avalonia.Skia.PlatformRenderInterface.LoadBitmapToWidth(Stream stream, Int32 width, BitmapInterpolationMode interpolationMode) in /_/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs:line 124
   at Avalonia.Media.Imaging.Bitmap.DecodeToWidth(Stream stream, Int32 width, BitmapInterpolationMode interpolationMode) in /_/src/Avalonia.Visuals/Media/Imaging/Bitmap.cs:line 24

I believe it is due to using SkiaSharp 2.88.0-preview.178 since 0.10.11: mono/SkiaSharp#1752 mono/SkiaSharp#1551

To Reproduce

using (var memoryStream = new MemoryStream(path)) {
    var bitmap = Bitmap.DecodeToWidth(memoryStream, 80); 
}

Desktop (please complete the following information):

  • OS: Windows 10
  • Version 0.10.13
@danielmayost
Copy link
Contributor

I also had a problem with that.
It does not happen to me in all the pictures, only in some.

It should be noted that even in the images that this happens, new Bitmap(stream) works well, which allows in the meantime if the DecodeToWidth does not work to use new Bitmap(stream).

Fusion86 added a commit to Fusion86/Avalonia that referenced this issue Apr 21, 2022
@Fusion86
Copy link
Contributor

Would it be possible to implement the workaround suggested by @AndersMad in mono/SkiaSharp#1551 (comment)? Because that seems to solve the issue, and it doesn't look like SkiaSharp will fix the underlying bug anytime soon. I didn't create a PR because I don't know what (performance) implications this change might have.

Example: Fusion86@fa97014

@maxkatz6
Copy link
Member

@Fusion86 we are considering replace skiasharp bindings with our smaller solution. But before that and for 0.10 backports your idea would be great to have.

@Gillibald
Copy link
Contributor

Probably fixed by: mono/SkiaSharp#2045

@Fusion86
Copy link
Contributor

Probably fixed by: mono/SkiaSharp#2045

I tried building Avalonia with SkiaSharp 2.88.1-preview.1 (which includes mono/SkiaSharp#2045) and the issue still exists. That said, they did add the upstream issue to the v2.88.1 milestone, so maybe it'll be fixed in the full release.

grokys added a commit that referenced this issue Jul 26, 2022
Use the workaround from mono/SkiaSharp#1551 (comment) to load bitmaps.

Fixes #7773
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants