ImageSharp icon indicating copy to clipboard operation
ImageSharp copied to clipboard

ImageFormatException when loading GIF image on Android with Hybrid AOT mode

Open tranb3r opened this issue 4 years ago • 13 comments

Description

When enabling Hybrid AOT mode on Android, GIF images cannot be loaded by ImageSharp (ImageFormatException).

Steps to Reproduce

Load GIF image in a Xamarin app on android. Make sure to enable hybrid aot mode in csproj (requires VS 2019 16.8 preview because of a regression in 16.7.*).

System Configuration

  • ImageSharp version: 1.0.1
  • Environment : Xamarin Android

tranb3r avatar Sep 03 '20 13:09 tranb3r

Do you have a stacktrace?

JimBobSquarePants avatar Sep 03 '20 14:09 JimBobSquarePants

The Gif would be also very helpful.

antonfirsov avatar Sep 03 '20 14:09 antonfirsov

Any gif. For example, base_1x4.gif from the test suite.

Here is the stacktrace:

SixLabors.ImageSharp.UnknownImageFormatException: Image cannot be loaded. Available decoders:
- GIF : GifDecoder
- JPEG : JpegDecoder
- BMP : BmpDecoder
- PNG : PngDecoder
- TGA : TgaDecoder

 at SixLabors.ImageSharp.Image.Load(SixLabors.ImageSharp.Configuration configuration, System.IO.Stream stream, SixLabors.ImageSharp.Formats.IImageFormat& format)
 at SixLabors.ImageSharp.Image.Load(System.IO.Stream stream, SixLabors.ImageSharp.Formats.IImageFormat& format)
 at ....

tranb3r avatar Sep 03 '20 14:09 tranb3r

And it's only Gifs yeah?

All other image formats work ok and use the same stream loading pipeline?

JimBobSquarePants avatar Sep 03 '20 15:09 JimBobSquarePants

Yes ,this exception is only happening for GIF images. With PNG files I'm also having an issue when enabling Hybrid AOT, but it's probably something else and I'm working on it to provide more details.

tranb3r avatar Sep 03 '20 15:09 tranb3r

About PNG files: Image.Load does not throw any exception The loaded image object has correct width and height. However, the loaded image is totally blank !

tranb3r avatar Sep 03 '20 20:09 tranb3r

@tranb3r i have just tried to reproduce this, but i was able to load the base_1x4.gif fine.

I have just added to the project file:

<AotAssemblies>true</AotAssemblies>
<AndroidAotMode>Hybrid</AndroidAotMode>

Is that all what's needed or do i miss something? Maybe you could you share your project file?

Im using VS Version 16.8.0 Preview 2.1

brianpopow avatar Sep 05 '20 15:09 brianpopow

@brianpopow Thank you for testing. Yes, that's all you need to add to the project file (in the Release section of course).

tranb3r avatar Sep 05 '20 16:09 tranb3r

@tranb3r i really did placed it in the debug section instead of the Release one 😬

Unfortunately i still cannot reproduce the issue. The app now crashes immediately when started. My experience with app's is very limited, so im not sure why that's happening. I have just added the two lines mentioned above to a blank xamarin project.

brianpopow avatar Sep 06 '20 12:09 brianpopow

I think hybrid aot is limited to 64bit arch. Which device are you testing on ?

tranb3r avatar Sep 06 '20 12:09 tranb3r

ok so that may be the reason then, my device has a ARMv7, so its 32bit. Is it possible to reproduce this with an emulator?

brianpopow avatar Sep 06 '20 12:09 brianpopow

I'm not sure it'll work on the emulator. I think it's only for arm64-v8a devices.

tranb3r avatar Sep 06 '20 13:09 tranb3r

We need someone to raise an issue upstream here for us to track. We can't fix issues with the AOT compiler.

JimBobSquarePants avatar Oct 13 '20 16:10 JimBobSquarePants

I'm going to close this. It's been several years without any update on upstream issues raised..

JimBobSquarePants avatar Jan 23 '23 12:01 JimBobSquarePants