Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

IImageViewHandler + Task.Delay, can cause infinite image loading on Android #13118

Open
jonathanpeppers opened this issue Dec 11, 2020 · 0 comments
Labels
blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. i/regression t/bug 🐛
Milestone

Comments

@jonathanpeppers
Copy link
Member

jonathanpeppers commented Dec 11, 2020

Description

Steps to Reproduce

  1. Create a new Xamarin.Forms project Flyout template
  2. Add an IImageViewHandler
  3. When the app runs, you can see Xamarin.Forms load images continuously in a loop.
[assembly: ExportImageSourceHandler(typeof(FileImageSource), typeof(Android.Glide.ImageViewHandler))]
//...
public class ImageViewHandler : IImageViewHandler
{
	public async Task LoadImageAsync(ImageSource source, ImageView imageView, CancellationToken token = default)
	{
		Log.Debug("IVH", "IImageViewHandler of type `{0}`, `{1}` called.", GetType(), nameof(LoadImageAsync));
		if (source is FileImageSource file)
		{
			var drawable = ResourceManager.GetDrawableByName(file.File);
			if (drawable != 0)
			{
				Log.Debug("IVH", "Loading `{0}` as an Android resource", file.File);

				// Comment this line to fix it
				await Task.Delay(10);

				imageView.SetImageResource(drawable);
			}
		}
	}
}

I found this from a bug report of a developer using glidex.forms:

jonathanpeppers/glidex#87

Expected Behavior

The images load once.

Actual Behavior

The images appears to load over and over indefinitely.

Basic Information

  • Version with issue: 4.8.0.1451 and 5.0.0.1558-pre3
  • Last known good version: 4.5.0.356 definitely worked, no idea which version broke.
  • Platform Target Frameworks:
    • Android: 30 or 28
  • Android Support Library / AndroidX Version:
  • Affected Devices: all

Device Logs

The attached sample logs this over and over:

[IVH] Loading `icon_about.png` as an Android resource
[IVH] IImageViewHandler of type `Android.Glide.ImageViewHandler`, instance created.
[IVH] IImageViewHandler of type `Android.Glide.ImageViewHandler`, `LoadImageAsync` called.
[IVH] Loading `icon_about.png` as an Android resource
[IVH] IImageViewHandler of type `Android.Glide.ImageViewHandler`, instance created.
[IVH] IImageViewHandler of type `Android.Glide.ImageViewHandler`, `LoadImageAsync` called.
[IVH] Loading `icon_about.png` as an Android resource
[IVH] IImageViewHandler of type `Android.Glide.ImageViewHandler`, instance created.
[IVH] IImageViewHandler of type `Android.Glide.ImageViewHandler`, `LoadImageAsync` called.
[IVH] Loading `icon_feed.png` as an Android resource
[IVH] IImageViewHandler of type `Android.Glide.ImageViewHandler`, instance created.
[IVH] IImageViewHandler of type `Android.Glide.ImageViewHandler`, `LoadImageAsync` called.
[IVH] Loading `icon_feed.png` as an Android resource
[IVH] IImageViewHandler of type `Android.Glide.ImageViewHandler`, instance created.
[IVH] IImageViewHandler of type `Android.Glide.ImageViewHandler`, `LoadImageAsync` called.
[IVH] Loading `icon_feed.png` as an Android resource
[IVH] IImageViewHandler of type `Android.Glide.ImageViewHandler`, instance created.
[IVH] IImageViewHandler of type `Android.Glide.ImageViewHandler`, `LoadImageAsync` called.
[IVH] Loading `icon_feed.png` as an Android resource

Reproduction Link

Note you might need to change the Task.Delay(1) to a higher number to see the problem more frequently:

App96.zip

Workaround

Only workaround is to not use glidex.forms, or comment out the Task.Delay(1) in my example.

@jonathanpeppers jonathanpeppers added t/bug 🐛 s/unverified New report that has yet to be verified labels Dec 11, 2020
@samhouts samhouts added this to New in Triage Dec 11, 2020
@jonathanpeppers jonathanpeppers changed the title IImageViewHandler + , can cause infinite image loading on Android IImageViewHandler + Task.Delay, can cause infinite image loading on Android Dec 11, 2020
@PureWeen PureWeen moved this from New to Ready For Work in Triage Dec 11, 2020
@PureWeen PureWeen added this to the 5.0.0 milestone Dec 11, 2020
@PureWeen PureWeen added i/regression and removed s/unverified New report that has yet to be verified labels Dec 11, 2020
@PureWeen PureWeen added this to To do in vNext+1 (5.0.0) via automation Dec 11, 2020
@PureWeen PureWeen added the blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. label Dec 11, 2020
@Redth Redth moved this from Ready For Work to Needs Estimate in Triage Dec 15, 2020
@Redth Redth added this to To do in v5.0.1 via automation Dec 18, 2020
@Redth Redth removed this from To do in vNext+1 (5.0.0) Dec 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. i/regression t/bug 🐛
Projects
Triage
  
Needs Estimate
v5.0.1
To do
Development

No branches or pull requests

2 participants