I'm getting
[libc] Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0xff1b5ffc in tid 1579 (tipass.MyApp), pid 1579 (tipass.MyApp)
when trying to set Source of Image (on android).
I understand that the reason of this error usually is InvokeOnMainThread or something like that, but can not find out what exactly. I would be grateful for any suggestions
XAML:
<Image Source="{Binding GifImageSource, Converter={StaticResource byteArrayToImageSourceConverter}}" IsAnimationPlaying="True" BindingContext="{Binding Ticket}" IsVisible="{Binding IsActivated}" RotationY="{Binding GifRotationY}" Aspect="AspectFill"/>
byteArrayToImageSourceConverter - is a converter from Xamarin Community Toolkit
ViewModel:
await MainThread.InvokeOnMainThreadAsync(async () => {
var bytes = ResourceFileToBytes("img.gif");
GifImageSource = bytes;
});
public static byte[] ResourceFileToBytes(string r)
{
var assembly = typeof(ByteArrayHelper).GetTypeInfo().Assembly;
byte[] buffer = null;
using (var stream = assembly.GetManifestResourceStream($"MyApp.Resources.{r}"))
{
if (stream != null)
{
long length = stream.Length;
buffer = new byte[length];
stream.Read(buffer, 0, (int)length);
}
}
return buffer;
}
img.gif is placed in Resources folder, build action = embeddedResource
EDIT:
Removed converter from XAML:
XAML:
<Image Source="{Binding GifImageSource}" IsAnimationPlaying="True" BindingContext="{Binding Ticket}" IsVisible="{Binding IsActivated}" RotationY="{Binding GifRotationY}" Aspect="AspectFill"/>
ViewModel:
await MainThread.InvokeOnMainThreadAsync(async () => {
var bytes = ByteArrayHelper.ResourceFileToBytes("img.gif");
var stream1 = new MemoryStream(bytes);
Ticket.GifImageSource = ImageSource.FromStream(() => stream1);
});
The result is the same:
[libc] Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0xff1b5ff8 in tid 4839 (tipass.MyApp), pid 4839 (tipass.MyApp)
What am I doing wrong?
EDIT:
found my problem on xamarin's github:
[Bug] ImageSource.FromStream() causes Android to crash with animated .gif files. #10895
https://github.com/xamarin/Xamarin.Forms/issues/10895