Glide: crash bug

Created on 22 Dec 2017  路  8Comments  路  Source: bumptech/glide


Glide Version: 4.3.0


Integration libraries:


Device/Android Version:


Issue details / Repro steps / Use case background:


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

SplashActivity.class:
 @Override
    protected void onResume() {
        super.onResume();
        GlideUtils.loadGifFromLocal(mContext, R.mipmap.gif_logo, mIvContent, 1);
    }

GlideUtils:
public static void loadGifFromLocal(Context context, int res, ImageView iv, int loopCount) {
        iv.clearAnimation();
        Glide.with(context)
                .asGif()
                .listener(new RequestListener<GifDrawable>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
                        resource.startFromFirstFrame();
                        resource.setLoopCount(loopCount);
                        resource.stop();
                        return false;
                    }
                })
                .load(res)
                .into(iv);
    }


Layout XML:

<FrameLayout xmlns:android="...


Stack trace / LogCat:

java.lang.RuntimeException: Unable to resume activity {cn.neoclub.uki.debug/cn.neoclub.uki.ui.activity.SplashActivity}: java.lang.IllegalArgumentException: Can't restart a running animation
question stale

All 8 comments

Please provide the full stack trace

@sjudd
Stack trace / LogCat:

12-22 19:01:58.985 17242 17242 W dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41f63d58)
12-22 19:01:59.185 17242 17242 E AndroidRuntime: FATAL EXCEPTION: main
12-22 19:01:59.185 17242 17242 E AndroidRuntime: Process: cn.neoclub.uki.debug, PID: 17242
12-22 19:01:59.185 17242 17242 E AndroidRuntime: java.lang.RuntimeException: Unable to resume activity {cn.neoclub.uki.debug/cn.neoclub.uki.ui.activity.SplashActivity}: java.lang.IllegalArgumentException: Can't restart a running animation
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2932)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2961)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1285)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:102)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:136)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:5426)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at java.lang.reflect.Method.invokeNative(Native Method)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Method.java:515)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at dalvik.system.NativeStart.main(Native Method)
12-22 19:01:59.185 17242 17242 E AndroidRuntime: Caused by: java.lang.IllegalArgumentException: Can't restart a running animation
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at com.bumptech.glide.util.Preconditions.checkArgument(Preconditions.java:17)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at com.bumptech.glide.load.resource.gif.GifFrameLoader.setNextStartFromFirstFrame(GifFrameLoader.java:232)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at com.bumptech.glide.load.resource.gif.GifDrawable.startFromFirstFrame(GifDrawable.java:162)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at cn.neoclub.uki.util.GlideUtils$3.onResourceReady(GlideUtils.java:169)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at cn.neoclub.uki.util.GlideUtils$3.onResourceReady(GlideUtils.java:161)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at com.bumptech.glide.request.SingleRequest.onResourceReady(SingleRequest.java:555)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at com.bumptech.glide.request.SingleRequest.onResourceReady(SingleRequest.java:530)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at com.bumptech.glide.request.SingleRequest.begin(SingleRequest.java:246)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:569)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:626)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at cn.neoclub.uki.util.GlideUtils.loadGifFromLocal(GlideUtils.java:176)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at cn.neoclub.uki.ui.activity.SplashActivity.onResume(SplashActivity.java:200)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1199)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at cn.jiguang.a.a.d.a.a.d.callActivityOnResume(Unknown Source)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at android.app.Activity.performResume(Activity.java:5380)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2922)
12-22 19:01:59.185 17242 17242 E AndroidRuntime:    ... 10 more

Call stop before startFromFirstFrame?

@sjudd
It may works;
Actually, I just want to play a local gif once without repeat, if there is any other way to play a local gif just once and stop;

stop(), setLoopCount(1), start()?

The GIF is started by the ImageViewTarget subclass, so you can also write your own ViewTarget implementation to avoid having to call stop().

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

@sjudd actually, calling resource.stop() doesn't help 馃槃

                            override fun onResourceReady(resource: GifDrawable, model: Any?, target: Target<GifDrawable>, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
                                resource.stop()
                                resource.startFromFirstFrame()

Results in

    java.lang.IllegalArgumentException: Can't restart a running animation
        at com.bumptech.glide.util.Preconditions.checkArgument(Preconditions.java:19)
        at com.bumptech.glide.load.resource.gif.GifFrameLoader.setNextStartFromFirstFrame(GifFrameLoader.java:237)
        at com.bumptech.glide.load.resource.gif.GifDrawable.startFromFirstFrame(GifDrawable.java:208)

Because it stops the GifDrawable but does not stop the GifFrameLoader

I also won't figure out how to make a custom Target, that looks a bit messy tbh.

I was getting the same exception when running it inside the view holder. I was trying to make the GIF start from the beginning with adapter.notifyItemChanged();. My solution was to keep an instance of the GifDrawable resource in the activity

Was this page helpful?
0 / 5 - 0 ratings

Related issues

piedpiperlol picture piedpiperlol  路  3Comments

billy2271 picture billy2271  路  3Comments

kenneth2008 picture kenneth2008  路  3Comments

Ncit picture Ncit  路  3Comments

Morteza-Rastgoo picture Morteza-Rastgoo  路  3Comments