glide icon indicating copy to clipboard operation
glide copied to clipboard

Failed to load a gif.

Open ZouYongpeng opened this issue 2 years ago • 3 comments

I found Glide cannot load this gif at all android devices, like Pixel 3 XL. bug_2

My code:

build.gradle

dependencies {
    // Glide
    implementation 'com.github.bumptech.glide:glide:4.13.2'
}

MainActivity

private fun loadGif() {
        Glide.with(this)
            .asGif()
            .load(R.drawable.bug_2)
            .listener(loadGifListener)
            .into(imageView)
    }

private val loadGifListener: RequestListener<GifDrawable> = object : RequestListener<GifDrawable> {

        override fun onLoadFailed(
            e: GlideException?,
            model: Any?,
            target: Target<GifDrawable>?,
            isFirstResource: Boolean
        ): Boolean {
            Log.d(TAG, "gif onLoadFailed: ")
            return false
        }

        override fun onResourceReady(
            resource: GifDrawable?,
            model: Any?,
            target: Target<GifDrawable>?,
            dataSource: DataSource?,
            isFirstResource: Boolean
        ): Boolean {
            Log.d(TAG, "gif onResourceReady: ")
            return false
        }
    }

Error log:

2022-12-14 14:38:21.780 9694-9694/com.zyp.glidedemo W/Glide: Load failed for 2131165280 with size [666x1262]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
      Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{AssetInputStream->GifDrawable->GifDrawable}, LOCAL
        Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{AssetInputStream->GifDrawable->GifDrawable}
2022-12-14 14:38:21.780 9694-9694/com.zyp.glidedemo D/GlideDemo: gif onLoadFailed: 

My analysis: I think this Gif format is special and Glide can't parse it successfully. glide_bug_1 glide_bug_2

ZouYongpeng avatar Dec 14 '22 06:12 ZouYongpeng

I also found another problematic gif file.

The log is as follows W/Glide: Load failed for [content://com.oplus.wallpapers.fileProvider/gallery_pictures/storage/emulated/0/DCIM/Camera/gif_load_error_9e_05_04_00_3b.gif] with dimensions [382x720] class com.bumptech.glide.load.engine.GlideException: Failed to load resource Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{AutoCloseInputStream->GifDrawable->GifDrawable}, LOCAL Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{AutoCloseInputStream->GifDrawable->GifDrawable}

Through breakpoint debugging, I found that GifHeaderParser.read() threw an exception when parsing the file, resulting in a status of STATUS_FORMAT_ERROR.

The exception code is currByte = rawData.get() & MASK_INT_LOWEST_BYTE; I think it may be that BufferUnderflowException is thrown when the rawData.get() method is executed. Does Glide have a plan to ensure that the effective data length in ByteBuffer is sufficient or perform exception handling?

Does Glide have any format requirements for Gif files? This Gif file starts with "47 49 46 38 39 61" and ends with "3b". I can't determine whether there is a problem with the Gif file format, after all, it can be displayed normally on other apps.

What frustrates me is that I can't upload the problematic gif file and the screenshot of the breakpoint debugging code.

ZouYongpeng avatar May 31 '23 14:05 ZouYongpeng

Failed DecodePath{AssetInputStream->GifDrawable->GifDrawable}

Has it been resolved? I also encountered this problem

WoKee avatar Aug 28 '24 03:08 WoKee

It looks like the original GIF fails to load because it was created with an old encoder (Animagic 1997), which adds non-standard metadata and uses legacy transparency/disposal methods. This causes issues with modern libraries like Glide. After re-saving the GIF using a modern tool (such as GIMP, or ezgif.com), it now loads correctly in Glide. Please see the attached video for a demo of the fixed behaviour.

https://github.com/user-attachments/assets/615dc580-c0c2-4181-ad0f-0493cc7be235

AbhisKmr avatar May 27 '25 17:05 AbhisKmr