Xamarin.Forms - iOS app crashes when one image is used multiple times on one page
See original GitHub issueDescription
We have an issue with FFImageLoading used in Xamarin.Forms (iOS). Based on this repo https://github.com/twintechs/TwinTechsFormsLib/blob/master/TwinTechsForms/TwinTechsForms.Core/XLabs/Forms/Controls/GridView.cs we have adapted GridView control to our needs. It works pretty well, but recently we have noticed important issue connected with FFImageLoading.
We have created a carousel with some tiles with images. Sometimes there is situation when one image is used multiple times (5-10, for instance as a placeholder). On Android everything is ok, but iOS happens to crash, without any crash log even in Visual Studio.
We have found some workaround. App is working when you force to use disk cache: this.CoverImage.CacheType = FFImageLoading.Cache.CacheType.Disk;
but when this happens, not all the images are visible on start.
Steps to Reproduce
Use one image multiple times on one page in UICollectionView
Expected Behavior
App is working, all images are visible
Actual Behavior
App crashes
Basic Information
- Version with issue: 2.3.6 - 2.4.3.840, happens earlier also, but this version was tested often
- Last known good version: none
- Platform: Xamarin.Forms - iOS
Reproduction Link / Code
FastCell concept: https://github.com/twintechs/TwinTechsFormsLib/blob/master/TwinTechsForms/TwinTechsForms.Core/TwinTechs/Controls/FastCell.cs
public partial class AssetCell : FastCell
{
protected override void InitializeCell()
{
this.InitializeComponent();
}
public override void OnBindingContextUpdated(bool isNewBindingContext)
{
if (this.BindingContext == null)
{
return;
}
var model = this.BindingContext as IgoListTileModel;
if (model == null)
{
return;
}
// Cover image is ffimageloading control
this.CoverImage.Source = null;
// This one crashes sometimes
this.CoverImage.Source = model.CoverImageUrl;
}
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:9 (1 by maintainers)
Top GitHub Comments
@daniel-luberda Hello. May be this info will be useful for troubleshooting this issue:
So we experienced very similar issue without FastCell approach, but because of our own issue in bindings which caused almost simultaneous loading of one same image for one same CachedImage view twice. Let’s say we have object with two fields:
And CachedImage view is binded like that Source = {Binding Source} Then when we are changing related row in db and receive callback that data is changed. After that we are copying all changed properties from new object to one which is already binded. We are actually working with lists of such objects but in simplistic way it can looks like that:
So here because of issue in our code OnProperyChanged called twice for Source - first time when we actually set source directly and second time when we set Url. After that in second or so(I think after image is loaded once or two times) we receive crash. It’s not reproducible constantly, but on Ipad Pro 11 with ~6-8 of such attachments(for each of them such simultaneous loading is triggered) - it was reproducible almost in 98%. I guess that bigger number of processor cores leads to bigger number of threads in the thread pull which used for images loading - which is increasing chance of race condition which finally leads to the crash(or vise versa less cores and less threads produce condition for that - but I never were able to reproduce it on simulator and on some devices it is reproducible more often then on others).
From our side we fixed this issue by fixing a way how we are updating our objects - so we are no more triggering this simultaneous loading of same image for same view. But even if it’s not correct usage of library - I anyway think that it should not crash in this case, because probably there are some valid cases (like this FastCell approach described above) where it can be reproducible.
There are also crash log but it’s not very helpful(Thread 25 shows FFImageLoader work but nothing useful I think):
And thank you for your work on this library! ;-D
Hi @daniel-luberda , are there any updates…?