microspaze / FFImageLoading.Maui

FFImageLoading.Maui - Fast & Furious Image Loading for .NET MAUI
MIT License
117 stars 18 forks source link

NSInternalInconsistencyException when loading certain animated images and applying a transform #47

Closed kpespisa closed 2 months ago

kpespisa commented 2 months ago

Description

Loading certain animated images and applying a transform to them causes a crash that loops.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={0, 0}, scale=3.000000, bitmapInfo=0x2002. Use UIGraphicsImageRenderer to avoid this assert.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001804ae0f8 __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x0000000180087db4 objc_exception_throw + 56
    2   Foundation                          0x0000000180d1718c -[NSMutableDictionary(NSMutableDictionary) classForCoder] + 0
    3   UIKitCore                           0x0000000184f77304 _UIGraphicsBeginImageContextWithOptions + 564
    4   FFImageLoadingTransformIssue        0x000000010068995c interp_to_native_trampoline + 156
    5   libmonosgen-2.0.dylib               0x000000010314376c ves_pinvoke_method + 584
    6   libmonosgen-2.0.dylib               0x0000000103137ef8 mono_interp_exec_method + 3052
    7   libmonosgen-2.0.dylib               0x00000001031359c0 inter
2024-08-26 21:14:44.163828-0400 FFImageLoadingTransformIssue[29143:8916612] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={0, 0}, scale=3.000000, bitmapInfo=0x2002. Use UIGraphicsImageRenderer to avoid this assert.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001804ae0f8 __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x0000000180087db4 objc_exception_throw + 56
    2   Foundation                          0x0000000180d1718c -[NSMutableDictionary(NSMutableDictionary) classForCoder] + 0
    3   UIKitCore                           0x0000000184f77304 _UIGraphicsBeginImageContextWithOptions + 564
    4   FFImageLoadingTransformIssue        0x000000010068995c interp_to_native_trampoline + 156
    5   libmonosgen-2.0.dylib               0x000000010314376c ves_pinvoke_method + 584
    6   libmonosgen-2.0.dylib               0x0000000103137ef8 mono_interp_exec_method + 3052
    7   libmonosgen-2.0.dylib               0x00000001031359c0 inter

... repeats many times ....

Steps to Reproduce

Add a CachedImage to a ContentPage and include a CircleTransformation. Set the source to a certain kind of animated image (I've provided an example). I've seen this with several images, and haven't determined what is special about them. Most load just fine.

Expected Behavior

Image loads and animates, OR fails to load similar to trying to load from an invalid URL

Actual Behavior

Image fails to load and an exception and stack trace are logged. The console fills up quickly until the app finally crashes.

Basic Information

Reproduction Link / Code

Project attached

FFImageLoadingTransformIssue.zip

microspaze commented 2 months ago

To walk-around, you can use CachedImageView instead like this:

            <maui:CachedImageView
                Source="mortalkombat.gif"
                Padding="20"
                Stroke="#DDDDDD" StrokeThickness="20" StrokeShape="Ellipse"
                HeightRequest="200"
                WidthRequest="200"
                Aspect="AspectFit"
                SemanticProperties.Description="dot net bot in a race car number eight">
            </maui:CachedImageView>    

https://github.com/user-attachments/assets/d29f0fe4-e122-47ee-b9d6-7be537ce9b28

For the crash root cause I will take a deep look and try to fix in the next version of FFImageLoading.Maui.

microspaze commented 2 months ago

@kpespisa Fixed in the latest version 1.2.7 : https://www.nuget.org/packages/FFImageLoading.Maui/1.2.7

kpespisa commented 2 months ago

I'm getting an error moving from 1.2.6 to 1.2.7:

System.InvalidOperationException: Unable to resolve service for type 'FFImageLoading.IImageService' while attempting to activate...

microspaze commented 2 months ago

@kpespisa Yes, it also takes me 1 hour to find the root cause. You can try to upgrade Maui to the latest version by command: sudo dotnet workload update

kpespisa commented 2 months ago

Ahh, thank you very much for the quick fix and advice!