FFImageLoading icon indicating copy to clipboard operation
FFImageLoading copied to clipboard

Cannot redisplay this drawable, its resources have been disposed.

Open chamamo opened this issue 10 years ago • 16 comments

Hi,

I'm using ImageViewAsync in a RecyclerView with placeholder. My activity crash and closed unexpectedly with this exception:

System.InvalidOperationExceptionCannot redisplay this drawable, its resources have been disposed. at FFImageLoading.Drawables.SelfDisposingBitmapDrawable.SetIsDisplayed (Boolean isDisplayed) <0x94b5fbd0 + 0x00088> in :0 at FFImageLoading.Views.ManagedImageView.UpdateDrawableDisplayedState (Android.Graphics.Drawables.Drawable drawable, Boolean isDisplayed) <0x96330330 + 0x0006f> in :0 at FFImageLoading.Views.ManagedImageView.SetImageDrawable (Android.Graphics.Drawables.Drawable drawable) <0x9632ffa0 + 0x0006f> in :0 at FFImageLoading.Work.ImageLoaderTask.SetImageDrawable (Android.Widget.ImageView imageView, Android.Graphics.Drawables.Drawable drawable) <0x94b5f640 + 0x0002b> in :0 at FFImageLoading.Work.ImageLoaderTask+c__async4+c__AnonStoreyC.<>m__1 () <0x8ce6a0d0 + 0x0006b> in :0 at FFImageLoading.Helpers.MainThreadDispatcher+c__AnonStorey0.<>m__0 () <0x9632fe50 + 0x0002f> in :0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x8ce652a0 + 0x00024> in :0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x8ce64b98 + 0x000bb> in :0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x8ce64ab8 + 0x0008b> in :0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x965740a8 + 0x0003f> in :0 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () <0x96579748 + 0x00017> in :0 at FFImageLoading.Work.ImageLoaderTask+c__async4.MoveNext () <0x963488a8 + 0x00a8f> in :0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x8ce652a0 + 0x00024> in :0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x8ce64b98 + 0x000bb> in :0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x8ce64ab8 + 0x0008b> in :0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x965740a8 + 0x0003f> in :0 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () <0x9634a9e0 + 0x00017> in <filename unknown>:0 at FFImageLoading.Work.ImageLoaderTask+<PrepareAndTryLoadingFromCacheAsync>c__async0.MoveNext () <0x96341ce0 + 0x00457> in <filename unknown>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x8ce652a0 + 0x00024> in <filename unknown>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x8ce64b98 + 0x000bb> in <filename unknown>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x8ce64ab8 + 0x0008b> in <filename unknown>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x965740a8 + 0x0003f> in <filename unknown>:0 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () <0x9634a9e0 + 0x00017> in :0 at FFImageLoading.Work.WorkScheduler+c__AnonStoreyA+c__async9.MoveNext () <0x96340320 + 0x00463> in :0

chamamo avatar Mar 07 '16 08:03 chamamo

Please post your RecyclerView class, it will help for debug

molinch avatar Mar 07 '16 09:03 molinch

I put image url on OnBindViewHolder method and I have a custom ImageViewAsync:

[Register("namespace.droid.controls.SlgImageView")]
    public class SlgImageView : ImageViewAsync, ViewTreeObserver.IOnPreDrawListener
    {
        private bool isViewLoaded; 

        private string imageUrl;

        private bool lazyLoading;

        public SlgImageView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
        {
        }

        public SlgImageView(Context context, IAttributeSet attrs) : base(context, attrs)
        {
            this.ViewTreeObserver.AddOnPreDrawListener(this);
            this.Init(context, attrs);
        }

        public string ImageUrl
        {
            get
            {
                return this.imageUrl; 
            }

            set
            {
                this.imageUrl = value;
                if (!this.lazyLoading || this.isViewLoaded)
                    this.LoadImageRealy();
            }
        }

        public string ErrorImagePath
        {
            get;
            set;
        }

        public string DefaultImagePath
        {
            get;
            set;
        }

        public bool OnPreDraw()
        {
            if (this.lazyLoading && !this.isViewLoaded && !string.IsNullOrEmpty(this.imageUrl))
            {
                this.LoadImageRealy();
            }

            this.isViewLoaded = true;
            return true;
        }

        public override void SetImageBitmap(Android.Graphics.Bitmap bm)
        {
            base.SetImageBitmap(bm);
            System.GC.Collect(1);
        }

        private void LoadImageRealy()
        {
            var task = ImageService.LoadUrl(this.imageUrl)
                .TransparencyChannel(false);
            if (!string.IsNullOrEmpty(this.ErrorImagePath))
                task.ErrorPlaceholder(this.ErrorImagePath, FFImageLoading.Work.ImageSource.ApplicationBundle);
            if (!string.IsNullOrEmpty(this.DefaultImagePath))
                task.LoadingPlaceholder(this.DefaultImagePath, FFImageLoading.Work.ImageSource.ApplicationBundle);
            if (this.lazyLoading && (this.Width > 0 || this.Height > 0))
            {
                task.DownSample(this.Width, this.Height);
            }

            task.Into(this);
        }

        private void Init(Context context, IAttributeSet attrs)
        {
            var array = context.ObtainStyledAttributes(attrs, Resource.Styleable.SlgImageView);

            for (var i = 0; i < array.IndexCount; ++i)
            {
                var attr = array.GetIndex(i);
                switch (attr)
                {
                    case Resource.Styleable.SlgImageView_lazyLoading:
                        this.lazyLoading = array.GetBoolean(attr, false);
                        break;
                    case Resource.Styleable.SlgImageView_defaultImagePath:
                        this.DefaultImagePath = array.GetString(attr);
                        break;
                    case Resource.Styleable.SlgImageView_errorImagePath:
                        this.ErrorImagePath = array.GetString(attr);
                        break;
                    default:
                        break;
                }
            }

            array.Recycle();
        }
    }

I set ImageUrl in OnBindViewHolder method and lazyLoading is set to true.

chamamo avatar Mar 07 '16 09:03 chamamo

@chamamo Would it be possible to access your sample project? maybe via email?

molinch avatar Mar 07 '16 16:03 molinch

@chamamo any chance to send us a sample? I would love to investigate what happens

molinch avatar Mar 13 '16 19:03 molinch

I will prepare a sample project for you, i'm sorry I don't have time in this moment to do that.

chamamo avatar Mar 21 '16 12:03 chamamo

Hello - we are running into this issue as well. It is rare but it crashes the app. We had 15,000 sessions over the past week and it crashed 7 times so it is very hard to repro.

I understand it might be hard to fix based only on the stack trace below but do you have any hint where we could place try/catch to at least keep the app from crashing?

Here is the stack trace:

FFImageLoading.Drawables.SelfDisposingBitmapDrawable.SetIsDisplayed(bool isDisplayed) FFImageLoading.Views.ManagedImageView.UpdateDrawableDisplayedState(Drawable drawable, bool isDisplayed) FFImageLoading.Views.ManagedImageView.SetImageDrawable(Drawable drawable) FFImageLoading.Work.ImageLoaderTask.SetImageDrawable(ImageView imageView, Drawable drawable) FFImageLoading.Work.ImageLoaderTask.c__async4.c__AnonStoreyC.<>m__1() FFImageLoading.Helpers.MainThreadDispatcher.c__AnonStorey0.<>m__0() FFImageLoading.Work.ImageLoaderTask.LoadPlaceHolderAsync() FFImageLoading.Work.ImageLoaderTask.PrepareAndTryLoadingFromCacheAsync() FFImageLoading.Work.WorkScheduler.c__AnonStoreyA.LoadImage()

patook avatar Apr 12 '16 05:04 patook

@patook I added some new checks with: https://github.com/molinch/FFImageLoading/commit/3da78fc6b29b51551fde76f7f451d82f97331e6e

Could you test it? I'll try to make a new alpha nugets soon.

daniel-luberda avatar Apr 18 '16 19:04 daniel-luberda

Hi Daniel,

Your check-in looks good.

The only way I can test it is by pushing it to the app store, since it only happens maybe 1 out of 100 times.

If you have nugets that you think are stable and contain this fix, I’ll be happy to add them and push a new release.

Best regards

Tony

Patook

From: Daniel Luberda [mailto:[email protected]] Sent: Monday, April 18, 2016 12:30 PM To: molinch/FFImageLoading [email protected] Cc: patook [email protected] Subject: Re: [molinch/FFImageLoading] Cannot redisplay this drawable, its resources have been disposed. (#158)

@patook https://github.com/patook I added some new checks with: https://github.com/molinch/FFImageLoading/commit/3da78fc6b29b51551fde76f7f451d82f97331e6e 3da78fc

Could you test it? I'll try to make new alpha nugets soon.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/molinch/FFImageLoading/issues/158#issuecomment-211541962 https://github.com/notifications/beacon/ALyQzb0JddmrhWZSt64p002woWeAho2Fks5p49vGgaJpZM4Hqkn0.gif

patook avatar Apr 18 '16 19:04 patook

Hi @patook There will be new nugets: FFImageLoading 2.1 alpha, but with new version, all previously downloaded cache data will be invalidated as new version uses new DiskCache implementation (without using journal file). You can bypass it by providing old cache implementation in Initialize method (instead SimpleDiskCache, provide DiskCache)

daniel-luberda avatar Apr 18 '16 20:04 daniel-luberda

I see – in this case, we will wait for the beta since there are about 20,000 active sessions and we want to make sure the fix is stable.

Thank you!

From: Daniel Luberda [mailto:[email protected]] Sent: Monday, April 18, 2016 1:34 PM To: molinch/FFImageLoading [email protected] Cc: patook [email protected] Subject: Re: [molinch/FFImageLoading] Cannot redisplay this drawable, its resources have been disposed. (#158)

Hi @patook https://github.com/patook There will be new nugets: FFImageLoading 2.1 alpha, but with new version, all previously downloaded cache data will be invalidated as new version uses new DiskCache implementation (without using journal file).

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/molinch/FFImageLoading/issues/158#issuecomment-211565244 https://github.com/notifications/beacon/ALyQzSS0vGKu_dycF7Su9ksHEw7hjbTQks5p4-rIgaJpZM4Hqkn0.gif

patook avatar Apr 18 '16 20:04 patook

On second thought, since our number of crashes has gone up to 27 over the last week, I think we can try the alpha nugets whenever you have them available.

patook avatar Apr 24 '16 18:04 patook

@patook Please try newest 2.1.0-alpha2. Can you still reproduce it?

daniel-luberda avatar Apr 29 '16 14:04 daniel-luberda

OK I am migrating it over and will have a push out on Monday. Did you remove ClearCacheAsync? What is the replacement?

patook avatar Apr 29 '16 20:04 patook

Depending on your need it is now InvalidateCacheAsync (it can clear both, memory or disk only). Or directly InvalidateMemoryCache and InvalidateDiskCacheAsync.

molinch avatar Apr 29 '16 21:04 molinch

FYI I have pushed out the latest version which has this fix into production for the past 2 days. I am not seeing the crash in the latest version. I will wait till the end of the week to confirm that it is gone.

patook avatar May 04 '16 18:05 patook

Confirming this has not happened in the last two weeks in production app after 2.1

patook avatar May 15 '16 17:05 patook