Cannot redisplay this drawable, its resources have been disposed.
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 1+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
Please post your RecyclerView class, it will help for debug
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 Would it be possible to access your sample project? maybe via email?
@chamamo any chance to send us a sample? I would love to investigate what happens
I will prepare a sample project for you, i'm sorry I don't have time in this moment to do that.
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.
@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.
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
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)
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
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 Please try newest 2.1.0-alpha2. Can you still reproduce it?
OK I am migrating it over and will have a push out on Monday. Did you remove ClearCacheAsync? What is the replacement?
Depending on your need it is now InvalidateCacheAsync (it can clear both, memory or disk only).
Or directly InvalidateMemoryCache and InvalidateDiskCacheAsync.
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.
Confirming this has not happened in the last two weeks in production app after 2.1