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

GIF animation sometimes continues for a while even after clearing the target #1087

Closed
TWiStErRob opened this issue Mar 24, 2016 · 0 comments
Closed
Assignees
Milestone

Comments

@TWiStErRob
Copy link
Collaborator

Glide Version: 3.7.0
Integration libraries: N/A
Device/Android Version: Galaxy S4 / 4.4.2
Issue details / Repro steps / Use case background:
While investigating another issue I played around with an animated GIF (has 5 frames, and long delays). The setup is simple: show an image in a fragment on startup, and there's button to call Glide.clear(imageView).

In the below log you can see:

  • the load succeeded as expected
  • it showed frames 0,1,2,3
  • GLIDE: Clearing target is the button press
  • continued to load frames 4,0,1,2, ...

While on the UI:

  • placeholder while downloading image
  • frames 0,1,2,3
  • placeholder after pressing button

Weirdly it doesn't always happen, if the resource is loaded from memory cache, then after clearing there are no more frames loaded. This is because there's a placeholder and TransitionDrawable (see "Proposed fix" for more).

Glide load line / GlideModule (if any) / list Adapter code (if any):

Glide
    .with(context)
    .load(url)
    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
    .placeholder(R.drawable.glide_placeholder)
    .error(R.drawable.glide_error)
    .listener(new LoggingListener<String, GlideDrawable>())
    .into(new LoggingTarget<>(new GlideDrawableImageViewTarget(imageView)))
;

Stack trace / LogCat:

23.810 8055 I/GLIDE: Loading
23.820 8055 V/LoggingTarget: getRequest()
23.820 8055 V/LoggingTarget: setRequest(com.bumptech.glide.request.GenericRequest@42d00fe0)
23.820 8055 V/LoggingTarget: onStop()
23.820 8055 I/GLIDE: Loaded
23.820 8055 V/LoggingTarget: getSize(com.bumptech.glide.request.GenericRequest@42d00fe0)
23.820 8055 V/LoggingTarget: onLoadStarted(android.graphics.drawable.BitmapDrawable@42afab50)
23.820 8055 V/LoggingTarget: onStart()
23.871 8055 V/LoggingTarget: onSizeReady(com.bumptech.glide.request.GenericRequest@42d00fe0, 1080, 1677)
23.941 14390 V/DecodeJob: Decoded source from cache in 67.596434, key: EngineKey{https://cloud.githubusercontent.com/assets/2906988/14031433/1bfc4106-f20d-11e5-94c6-861bbf3f4991.gif+com.bumptech.glide.signature.EmptySignature@42d365d8+[1080x1677]+''+'ImageVideoBitmapDecoder.com.bumptech.glide.load.resource.bitmap'+''+'BitmapEncoder.com.bumptech.glide.load.resource.bitmap'+'GifBitmapWrapperDrawableTranscoder.com.bumptech.glide.load.resource.transcode'+''}
23.941 14390 V/DecodeJob: Transformed resource from source in 0.030518, key: EngineKey{https://cloud.githubusercontent.com/assets/2906988/14031433/1bfc4106-f20d-11e5-94c6-861bbf3f4991.gif+com.bumptech.glide.signature.EmptySignature@42d365d8+[1080x1677]+''+'ImageVideoBitmapDecoder.com.bumptech.glide.load.resource.bitmap'+''+'BitmapEncoder.com.bumptech.glide.load.resource.bitmap'+'GifBitmapWrapperDrawableTranscoder.com.bumptech.glide.load.resource.transcode'+''}
23.941 14390 V/DecodeJob: Transcoded transformed from source in 0.183105, key: EngineKey{https://cloud.githubusercontent.com/assets/2906988/14031433/1bfc4106-f20d-11e5-94c6-861bbf3f4991.gif+com.bumptech.glide.signature.EmptySignature@42d365d8+[1080x1677]+''+'ImageVideoBitmapDecoder.com.bumptech.glide.load.resource.bitmap'+''+'BitmapEncoder.com.bumptech.glide.load.resource.bitmap'+'GifBitmapWrapperDrawableTranscoder.com.bumptech.glide.load.resource.transcode'+''}
23.971 8055 V/GLIDE: .onResourceReady(GifDrawable@42d2f2e0(405x721), https://cloud.githubusercontent.com/assets/2906988/14031433/1bfc4106-f20d-11e5-94c6-861bbf3f4991.gif, LoggingTarget@42cfab68, async, first)
23.971 8055 V/LoggingTarget: onResourceReady(com.bumptech.glide.load.resource.gif.GifDrawable@42d2f2e0, com.bumptech.glide.request.animation.DrawableCrossFadeViewAnimation@42b01930)

23.971 8804 V/DecodeJob: Fetched data in 0.061035, key: EngineKey{0+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@14f35e5e+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
24.011 8804 V/DecodeJob: Decoded from source in 44.95239, key: EngineKey{0+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@14f35e5e+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
24.011 8804 V/DecodeJob: Transformed resource from source in 0.030517, key: EngineKey{0+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@14f35e5e+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
24.011 8804 V/DecodeJob: Transcoded transformed from source in 0.030518, key: EngineKey{0+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@14f35e5e+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}

25.973 8598 V/DecodeJob: Fetched data in 0.12207, key: EngineKey{1+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@afb05e7d+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
26.063 8598 V/DecodeJob: Decoded from source in 86.364746, key: EngineKey{1+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@afb05e7d+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
26.063 8598 V/DecodeJob: Transformed resource from source in 0.061035, key: EngineKey{1+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@afb05e7d+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
26.063 8598 V/DecodeJob: Transcoded transformed from source in 0.030518, key: EngineKey{1+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@afb05e7d+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}

29.977 8715 V/DecodeJob: Fetched data in 0.122071, key: EngineKey{2+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@808e194b+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
30.077 8715 V/DecodeJob: Decoded from source in 97.198487, key: EngineKey{2+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@808e194b+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
30.077 8715 V/DecodeJob: Transformed resource from source in 0.091552, key: EngineKey{2+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@808e194b+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
30.077 8715 V/DecodeJob: Transcoded transformed from source in 0.12207, key: EngineKey{2+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@808e194b+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}

30.977 8787 V/DecodeJob: Fetched data in 0.12207, key: EngineKey{3+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@74444e25+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
31.058 8787 V/DecodeJob: Decoded from source in 79.62035999999999, key: EngineKey{3+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@74444e25+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
31.058 8787 V/DecodeJob: Transformed resource from source in 0.061035, key: EngineKey{3+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@74444e25+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
31.058 8787 V/DecodeJob: Transcoded transformed from source in 0.030517, key: EngineKey{3+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@74444e25+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}

31.848 8055 I/GLIDE: Clearing target android.support.v7.widget.AppCompatImageView{42bfbe28 V.ED..C. ........ 0,0-1080,1677 #1020006 android:id/icon}
31.848 8055 V/LoggingTarget: onLoadCleared(android.graphics.drawable.BitmapDrawable@42afab50)
31.848 8055 I/GLIDE: Clearing target android.support.v7.widget.AppCompatImageView{42bfbe28 V.ED..C. ......ID 0,0-1080,1677 #1020006 android:id/icon} finished

34.991 8804 V/DecodeJob: Fetched data in 0.12207, key: EngineKey{4+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@e3a47037+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
35.051 8804 V/DecodeJob: Decoded from source in 68.206786, key: EngineKey{4+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@e3a47037+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
35.051 8804 V/DecodeJob: Transformed resource from source in 0.061035, key: EngineKey{4+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@e3a47037+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
35.061 8804 V/DecodeJob: Transcoded transformed from source in 0.091554, key: EngineKey{4+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@e3a47037+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}

35.992 8598 V/DecodeJob: Fetched data in 0.091552, key: EngineKey{0+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@559405aa+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
36.062 8598 V/DecodeJob: Decoded from source in 73.486328, key: EngineKey{0+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@559405aa+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
36.062 8598 V/DecodeJob: Transformed resource from source in 0.030518, key: EngineKey{0+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@559405aa+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
36.062 8598 V/DecodeJob: Transcoded transformed from source in 0.030517, key: EngineKey{0+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@559405aa+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}

38.004 8715 V/DecodeJob: Fetched data in 0.12207, key: EngineKey{1+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@ce952f7a+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
38.074 8715 V/DecodeJob: Decoded from source in 71.13647499999999, key: EngineKey{1+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@ce952f7a+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
38.074 8715 V/DecodeJob: Transformed resource from source in 0.061035, key: EngineKey{1+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@ce952f7a+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
38.074 8715 V/DecodeJob: Transcoded transformed from source in 0.061035, key: EngineKey{1+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@ce952f7a+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}

41.988 8787 V/DecodeJob: Fetched data in 0.12207, key: EngineKey{2+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@e6191b1a+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
42.088 8787 V/DecodeJob: Decoded from source in 97.53417999999999, key: EngineKey{2+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@e6191b1a+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
42.088 8787 V/DecodeJob: Transformed resource from source in 0.061035, key: EngineKey{2+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@e6191b1a+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}
42.088 8787 V/DecodeJob: Transcoded transformed from source in 0.030518, key: EngineKey{2+com.bumptech.glide.load.resource.gif.GifFrameLoader$FrameSignature@e6191b1a+[1080x1677]+''+'GifFrameResourceDecoder.com.bumptech.glide.load.resource.gif'+''+''+''+''}

...

Workaround:
Most of the time users won't experience this issue, becuase this continuous loading is stopped when a GC happens, but it's still a good idea to properly free resources.

Proposed fix:
I think the problem is in GlideDrawableImageViewTarget where onResourceReady resource.start() is called, but the animation is only stopped when the activity/fragment is stopped. I think that class needs to override another method too:

@Override public void onLoadCleared(Drawable placeholder) {
    if (resource != null) {
        resource.stop();
        resource = null;
    }
    super.onLoadCleared(placeholder);
}

The comment in GifDrawable.stop() says there's an automatic detection of "no longer in use". This doesn't work when the GifDrawable is part of a TransitionDrawable because that sets itself as callback to the GifDrawable. So the check that would clean up resources fails in onFrameReady. This only happens when a thumbnail or a placeholder was displayed with crossFade before the GIF load finished. This may worth fixing as well as part of this issue, for example changing getCallback() to something like findCallback():

/**
 * Find out if there's a real Callback registered to this Drawable.
 * In case of multiple layers of drawables, like in case of `TransitionDrawable`,
 * find the topmost callback.
 */
private Callback findCallback() {
    Callback callback = getCallback();
    while (callback instanceof Drawable) {
        callback = ((Drawable)callback).getCallback();
    }
    return callback;
}
@sjudd sjudd added v3 and removed enhancement labels Sep 14, 2017
@sjudd sjudd added bug and removed bug v3 labels Nov 12, 2017
@sjudd sjudd added this to the 4.4 milestone Nov 19, 2017
@sjudd sjudd closed this as completed in 3dad449 Nov 19, 2017
@sjudd sjudd added the GIF label Nov 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants