Hello,
I get crash on Android using Xamarin.Forms 2.4.0 and FFImageLoading 2.2.22:
My xaml-page:
```
xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
xmlns:local="clr-namespace:Bug"
x:Class="Bug.ImgList">
SeparatorVisibility="None"
SeparatorColor="Transparent"
IsGroupingEnabled="True"
ItemsSource="{Binding ImageSrc}"
ItemSelected="OnItemSelected"
CachingStrategy="RecycleElement"
VerticalOptions="FillAndExpand">
Where ViewCell:
```<?xml version="1.0" encoding="UTF-8"?>
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
xmlns:ffimagetransforms="clr-namespace:FFImageLoading.Transformations;assembly=FFImageLoading.Transformations"
x:Class="Bug.ViewCell">
<Grid x:Name="ViewCell" Margin="0, 0, 0, 22" RowSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="72" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand" Grid.Column="0">
<ffimageloading:CachedImage
Aspect="AspectFit"
HeightRequest="40"
WidthRequest="40"
AbsoluteLayout.LayoutBounds="0.5, 0.5, AutoSize, AutoSize"
AbsoluteLayout.LayoutFlags="PositionProportional"
Source="{Binding Img}">
<ffimageloading:CachedImage.Transformations>
<ffimagetransforms:CircleTransformation/>
</ffimageloading:CachedImage.Transformations>
</ffimageloading:CachedImage>
<Label
Text="{Binding Text}"
FontSize="16"
TextColor="White"
AbsoluteLayout.LayoutBounds="0.5, 0.5, AutoSize, AutoSize"
AbsoluteLayout.LayoutFlags="PositionProportional"
IsVisible="{Binding HasText}"/>
</AbsoluteLayout>
</Grid>
</ViewCell>
ImageSrc class:
public class ImageSrc
{
public bool HasText { get; }
public string Text
{
get
{
return "TT";
}
}
public ImageSource Img { get; } //here some different source values - some from Android resources, some from stream.
}
Create at least several hundreds of items and start scrolling list view up and down – you’ll get crash (on Android 7.0) with one of the following errors:
“JNI ERROR (app bug): attempt to use stale global reference”
Or
“JNI ERROR (app bug): accessed deleted global reference”
Seems to be race condition somewhere in image loading.
I don't have any crashes when I use FFImageLoading version 2.2.6 and 2.2.11.
Hi @grasdy,
I used your code and cannot reproduce it. Could you make a working project out of the code you provided?
BTW: also using bindings in fast scrolling lists is a bad idea, read more here: https://github.com/luberda-molinet/FFImageLoading/wiki/Xamarin.Forms-Advanced#usage-in-listview-with-listviewcachingstrategyrecycleelement-enabled
Hi @daniel-luberda,
I created the project in Visual Studio 2017 that shows this crash.
Just build this project and deploy it on device with Android 7.0 or 6.0 (I also got this crash on Android 6.0). You should scroll ListView very fast for get this crash.
I also have saved Output-Debug.txt - output log file, with this crash (in archive).
Crash.zip
Hi,
I can confirm this "bug". Our customers started complaining about phone crashing in quite simple list view. I first though it was xamarin problem with list elements, but after removing FFImageLoading xaml element error stopped happening. I was able to reproduce error same way as grasdy explained here.
I debugged it. IMO it's still a Xamarin.Forms issue, that error cannot be reproduced when using newest 2.2.23 prerelease which uses fast renderers by default if possible (correct Xamarin.Forms version), when I disabled fast renderer, the error happened again. Probably too many views cause too many layout recalculations and too much load on a main thread.
Please let me know if you still experience it in 2.2.23 stable
I updated to 2.2.23 stable and it still seems to crash when fast scrolling, but I believe you are right about xamarin causing this error. I fixed this problem by removing caching strategy.
I updated to 2.2.23 and got this crash too. Removing CachingStrategy from ListView has fixed this problem.
I also tried to set CacheType="{x:Null}" for ffimageloading:CachedImage in ViewCell element (without removing CachingStrategy) and this crash became to show more difficult. I upload my project with this edits.
Crash2.zip
It seems like you're trying to draw an image into a view that has been collected by Java garbage collector. Have you checked this case?
It seems like you're trying to draw an image into a view that has been collected by Java garbage collector. Have you checked this case?
I don't think it's the case, this is checked before setting an image. See this:
I do not know much about xamarin.forms but just spent a whole day debugging an Xamarin vanilla android project that crashed without any usefull error.
I had the same errors
“JNI ERROR (app bug): attempt to use stale global reference”
Or
“JNI ERROR (app bug): accessed deleted global reference”
In my case the problem came from not cancelling the old loader task when loading a new image for recycled views in my gridview.
Maybe the task cancelling when recycling views is not functioning correctly in the forms implementation?
@Sevenish Previous task is cancelled before every image loading: https://github.com/luberda-molinet/FFImageLoading/blob/master/source/FFImageLoading.Forms.Droid/CachedImageFastRenderer.cs#L236
Maybe we should add some locks there?
Could you check if it's solved in 2.2.25?
@daniel-luberda I check version 2.2.25 and it's look like this bug is fixed. Thanks a lot!
Most helpful comment
@daniel-luberda I check version 2.2.25 and it's look like this bug is fixed. Thanks a lot!