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

On 4.3 Gifs do not always play #2541

Closed
perracodex opened this issue Oct 31, 2017 · 6 comments
Closed

On 4.3 Gifs do not always play #2541

perracodex opened this issue Oct 31, 2017 · 6 comments

Comments

@perracodex
Copy link

Device: Nexus 5X. Android 7.1.2

After trying 4.3 I can confirm that Gifs do not always play. Sometimes the same Gif file will not start to play at all, other times will play without problems, and other times will play but at slow motion.

I’ve tried with several different Gif files just to discard if it was a specific file, but the issue happens with any Gif file and not specific to any.

I’ve tried to find a pattern to reproduce the issue, but it happens randomly with any Gif file.

I can confirm that when reverting to 4.2 the issue disappears.

@sjudd
Copy link
Collaborator

sjudd commented Oct 31, 2017

I don't seem to be able to reproduce this with Glide's giphy sample. Are you able to with that sample app? Do you have another sample app you might be able to attach the reproduces the issue?

@michaeimm
Copy link
Contributor

I had the same problem in my application when bind view holder second time in recyclerView. Call drawable.start() every time can solve this problem temporarily.

Had something changed in 4.3 when Glide do clear?

@sjudd
Copy link
Collaborator

sjudd commented Nov 1, 2017

@michaeimm See my comment above. I don't think anything intentionally changed here. If you can provide some repro steps, or even the code you're using to work around the issue that would help.

@sjudd sjudd added this to the 4.4 milestone Nov 1, 2017
@michaeimm
Copy link
Contributor

@sjudd I got some gif from here and run Glide's gallery sample.

@foxware00
Copy link

I can confirm I am seeing the same behaviour when upgrading to 2.3.0

@sjudd sjudd modified the milestones: 4.4, 4.3.1 Nov 2, 2017
@sjudd sjudd added the bug label Nov 2, 2017
@sjudd
Copy link
Collaborator

sjudd commented Nov 2, 2017

Thanks @michaeimm I was able to reproduce with the same steps.

Introduced by 90b3b9f. The pendingDrawable, if present, is loaded synchronously when the GifDrawable is restarted.

The GifDrawable is restarted by ImageViewTarget prior to the GifDrawable being set on the View:

private void setResourceInternal(@Nullable Z resource) {
maybeUpdateAnimatable(resource);
setResource(resource);
}

As a result, getCallback() returns null, which causes the GifDrawable to immediately stop itself here:

@Override
public void onFrameReady() {
if (getCallback() == null) {
stop();
invalidateSelf();
return;
}

Calling start() in the Target after super.onResourceReady will fix the issue because the GIfDrawable has been set on the View and has a non-null callback.

11-02 07:33:48.601 W/System.err( 4103): java.lang.RuntimeException
11-02 07:33:48.601 W/System.err( 4103): 	at com.bumptech.glide.load.resource.gif.GifFrameLoader.stop(GifFrameLoader.java:173)
11-02 07:33:48.602 W/System.err( 4103): 	at com.bumptech.glide.load.resource.gif.GifFrameLoader.unsubscribe(GifFrameLoader.java:123)
11-02 07:33:48.602 W/System.err( 4103): 	at com.bumptech.glide.load.resource.gif.GifDrawable.stopRunning(GifDrawable.java:196)
11-02 07:33:48.602 W/System.err( 4103): 	at com.bumptech.glide.load.resource.gif.GifDrawable.stop(GifDrawable.java:178)
11-02 07:33:48.602 W/System.err( 4103): 	at com.bumptech.glide.load.resource.gif.GifDrawable.onFrameReady(GifDrawable.java:288)
11-02 07:33:48.602 W/System.err( 4103): 	at com.bumptech.glide.load.resource.gif.GifFrameLoader.onFrameReady(GifFrameLoader.java:267)
11-02 07:33:48.602 W/System.err( 4103): 	at com.bumptech.glide.load.resource.gif.GifFrameLoader.loadNextFrame(GifFrameLoader.java:213)
11-02 07:33:48.602 W/System.err( 4103): 	at com.bumptech.glide.load.resource.gif.GifFrameLoader.start(GifFrameLoader.java:168)
11-02 07:33:48.602 W/System.err( 4103): 	at com.bumptech.glide.load.resource.gif.GifFrameLoader.subscribe(GifFrameLoader.java:116)
11-02 07:33:48.602 W/System.err( 4103): 	at com.bumptech.glide.load.resource.gif.GifDrawable.startRunning(GifDrawable.java:189)
11-02 07:33:48.603 W/System.err( 4103): 	at com.bumptech.glide.load.resource.gif.GifDrawable.start(GifDrawable.java:171)
11-02 07:33:48.603 W/System.err( 4103): 	at com.bumptech.glide.request.target.ImageViewTarget.maybeUpdateAnimatable(ImageViewTarget.java:121)
11-02 07:33:48.603 W/System.err( 4103): 	at com.bumptech.glide.request.target.ImageViewTarget.setResourceInternal(ImageViewTarget.java:114)
11-02 07:33:48.603 W/System.err( 4103): 	at com.bumptech.glide.request.target.ImageViewTarget.onResourceReady(ImageViewTarget.java:93)
11-02 07:33:48.603 W/System.err( 4103): 	at com.bumptech.glide.request.SingleRequest.onResourceReady(SingleRequest.java:560)
11-02 07:33:48.603 W/System.err( 4103): 	at com.bumptech.glide.request.SingleRequest.onResourceReady(SingleRequest.java:530)
11-02 07:33:48.604 W/System.err( 4103): 	at com.bumptech.glide.request.SingleRequest.begin(SingleRequest.java:246)
11-02 07:33:48.604 W/System.err( 4103): 	at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:569)
11-02 07:33:48.604 W/System.err( 4103): 	at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:626)
11-02 07:33:48.604 W/System.err( 4103): 	at com.bumptech.glide.samples.gallery.RecyclerAdapter.onBindViewHolder(RecyclerAdapter.java:77)
11-02 07:33:48.604 W/System.err( 4103): 	at com.bumptech.glide.samples.gallery.RecyclerAdapter.onBindViewHolder(RecyclerAdapter.java:25)
11-02 07:33:48.604 W/System.err( 4103): 	at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6482)
11-02 07:33:48.605 W/System.err( 4103): 	at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6515)
11-02 07:33:48.605 W/System.err( 4103): 	at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5458)
11-02 07:33:48.605 W/System.err( 4103): 	at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5724)
11-02 07:33:48.605 W/System.err( 4103): 	at android.support.v7.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:285)
11-02 07:33:48.605 W/System.err( 4103): 	at android.support.v7.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:342)
11-02 07:33:48.605 W/System.err( 4103): 	at android.support.v7.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:358)
11-02 07:33:48.607 W/System.err( 4103): 	at android.support.v7.widget.GapWorker.prefetch(GapWorker.java:365)
11-02 07:33:48.607 W/System.err( 4103): 	at android.support.v7.widget.GapWorker.run(GapWorker.java:396)
11-02 07:33:48.607 W/System.err( 4103): 	at android.os.Handler.handleCallback(Handler.java:789)
11-02 07:33:48.607 W/System.err( 4103): 	at android.os.Handler.dispatchMessage(Handler.java:98)
11-02 07:33:48.607 W/System.err( 4103): 	at android.os.Looper.loop(Looper.java:164)
11-02 07:33:48.607 W/System.err( 4103): 	at android.app.ActivityThread.main(ActivityThread.java:6541)
11-02 07:33:48.608 W/System.err( 4103): 	at java.lang.reflect.Method.invoke(Native Method)
11-02 07:33:48.608 W/System.err( 4103): 	at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
11-02 07:33:48.608 W/System.err( 4103): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

sjudd added a commit to sjudd/glide that referenced this issue Nov 2, 2017
After 90b3b9f we have a case where a
GifDrawable may load a frame synchronously when it’s started. If the
GifDrawable was started before it was attached to a View (and gets a 
non-null Callback) and the GifDrawable had a frame pending, then the
GifDrawable would stop itself in the start() call, causing the 
drawable not to animate. We can avoid this scenario by changing the 
order in which we start animated drawables and set them on views so that
we only start the drawable after its set on the View.

Fixes bumptech#2541
@sjudd sjudd closed this as completed in aa2711b Nov 2, 2017
sjudd added a commit to sjudd/glide that referenced this issue Sep 24, 2021
After 90b3b9f we have a case where a
GifDrawable may load a frame synchronously when it’s started. If the
GifDrawable was started before it was attached to a View (and gets a 
non-null Callback) and the GifDrawable had a frame pending, then the
GifDrawable would stop itself in the start() call, causing the 
drawable not to animate. We can avoid this scenario by changing the 
order in which we start animated drawables and set them on views so that
we only start the drawable after its set on the View.

Fixes bumptech#2541
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

5 participants