Baseflow / flutter_cached_network_image

Download, cache and show images in a flutter app
https://baseflow.com
2.43k stars 654 forks source link

Failed to decode image #837

Open H-Bin opened 1 year ago

H-Bin commented 1 year ago

🐛 Bug Report

I found a bug on my android simulator, but I can't reproduce it. This bug only shows on CachedNetworkImage widget, Image.network works fine.

Expected behavior

When the bug happen, the image won't be shown and the console shows bug log.I run 'flutter clean' the bug still exists, but when I clean the app cache on simulator, the bug has been resolved, app works fine

Here is the bug log

Another exception was thrown: Exception: Invalid image data
D/EGL_emulation( 5595): app_time_stats: avg=93.80ms min=7.37ms max=2484.41ms count=32
E/FlutterJNI( 5595): Failed to decode image
E/FlutterJNI( 5595): android.graphics.ImageDecoder$DecodeException: Failed to create image decoder with message 'unimplemented'Input contained an error.
E/FlutterJNI( 5595):    at android.graphics.ImageDecoder.nCreate(Native Method)
E/FlutterJNI( 5595):    at android.graphics.ImageDecoder.access$200(ImageDecoder.java:172)
E/FlutterJNI( 5595):    at android.graphics.ImageDecoder$ByteBufferSource.createImageDecoder(ImageDecoder.java:242)
E/FlutterJNI( 5595):    at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1870)
E/FlutterJNI( 5595):    at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1863)
E/FlutterJNI( 5595):    at io.flutter.embedding.engine.FlutterJNI.decodeImage(FlutterJNI.java:524)

Reproduction steps

I can't reproduce it, but I guess it's related to cache

Configuration

Version: 3.2.1

Platform:

RefaatMojamel commented 1 year ago

I have same problem !

Leuow95 commented 1 year ago

I'm facing the same problem

abdelkadersebihi commented 1 year ago

same here!

asoap commented 1 year ago

Adding my voice to the choir. I just ran into this also. Clearing the cache in the simulator fixed it as well.

Nezzquikk commented 1 year ago

me too

midhlajnazar commented 1 year ago

i also have same issue , but not for all image, only for some image.

imijanur commented 11 months ago

Getting this error and also reporting in the crashlytics continuously.

How to reproduce ?

A broken url passed to the widget, server is responding 404 response with html. Its handling the UI with error widget but when navigating to to another route then generating error

======== Exception caught by image resource service ================================================ The following _Exception was thrown resolving an image codec: Exception: Invalid image data

When the exception was thrown, this was the stack:

0 _futurize (dart:ui/painting.dart:6950:5)

1 ImageDescriptor.encoded (dart:ui/painting.dart:6764:12)

2 instantiateImageCodecWithSize (dart:ui/painting.dart:2307:60)

3 PaintingBinding.instantiateImageCodecWithSize (package:flutter/src/painting/binding.dart:182:15)

4 ImageLoader.loadImageAsync. (package:cached_network_image/src/image_provider/_image_loader.dart:68:22)

5 ImageLoader._load (package:cached_network_image/src/image_provider/_image_loader.dart:129:27)

6 new MultiImageStreamCompleter. (package:cached_network_image/src/image_provider/multi_image_stream_completer.dart:26:7)

Image provider: CachedNetworkImageProvider("https://badshaitrading.com/ups/images/2023-05-27T06-07-11.159Zimage_cropper_1685167594491.jpg", scale: 1.0) Image key: CachedNetworkImageProvider("https://badshaitrading.com/ups/images/2023-05-27T06-07-11.159Zimage_cropper_1685167594491.jpg", scale: 1.0): CachedNetworkImageProvider("https://badshaitrading.com/ups/images/2023-05-27T06-07-11.159Zimage_cropper_1685167594491.jpg", scale: 1.0)

Any suggestion to resolve this ?

CC-LU commented 8 months ago

i also have same issue , but not for all image, only for some image.

me too...how could fix it ?

windinternet commented 6 months ago

这个问题比较笼统,主要还是集中在给定的url,无法正确获取到图片内容导致,也就无法正确解析出图片,就会出现这个错误。无法从给定的url获取到正确的图片内容原因有很多,以下几点可以参考: 1、网络不通畅,无法正确请求到服务器 2、有些图片需要身份验证,你的url可能缺少这部分内容,导致鉴权失败了 3、服务器返回的图片内容的确是坏的 4、这个组件加载图片默认使用的http方法好像不是get,如果服务端只做了get映射,也会导致请求不到图片 5、曾经因为各种原因加载失败过,这是我发现的新问题,我的图片因为上诉的原因之一导致加载失败,他把失败的结果也缓存起来了,在我手动清除缓存以前无论尝试多少次,仍然是失败的,我准备提一个问题:加载失败的状态不应该被缓存

上诉的可能,基本有一种通用的判断方法:直接把url打印出来,直接到浏览器中访问,如果浏览器能打开而这个组件依旧不行,就重点检查下4和5。

This question is quite general, mainly focusing on the given url. The inability to correctly obtain the content of the image leads to an inability to properly parse the image, which results in this error. There are many reasons why the correct image content cannot be obtained from the given url. Here are a few points of reference:

  1. The network is not smooth, and it is impossible to make a correct request to the server.
  2. Some images require identity authentication. Your url may lack this content, resulting in a failure of authentication.
  3. The image content returned by the server is indeed bad.
  4. The default http method for this component to load images seems to not be get. If the server only performs a get mapping, it will also cause the image to not be requested.
  5. It has failed to load due to various reasons in the past. This is a new problem I discovered. Because my images failed to load for one of the above reasons, it also cached the failed results. Before I manually clear the cache, no matter how many times I try, it still fails. I plan to raise a question: the failed loading status should not be cached.

The above possibilities basically have a general judgment method: directly print out the url and visit it directly in the browser. If the browser can open it but this component still doesn't work, focus on checking 4 and 5.

max-anders commented 2 weeks ago

for me, I just uninstalled the app on the emulator and reinstalled and it was gone, looks like a bug

windinternet commented 1 week ago

We recommend using fast_cached_network_image, which is more powerful, user-friendly, and intelligent. It can be easily obtained on dart pub!