Xamarin.forms: [Bug] ImageButtonRenderer caused crash

Created on 29 Mar 2020  路  15Comments  路  Source: xamarin/Xamarin.Forms

Description

I received a crash log in appcenter with following stacktrace. I've no steps to reproduce )-:

Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.

Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.
java.lang.Error: Java callstack:
crc643f46942d9dd1fff9.ImageButtonRenderer.n_invalidate(Native Method)
crc643f46942d9dd1fff9.ImageButtonRenderer.invalidate(Unknown Source:0)
android.view.ViewRootImpl$InvalidateOnAnimationRunnable.run ViewRootImpl.java:7399
android.view.Choreographer$CallbackRecord.run Choreographer.java:949
android.view.Choreographer.doCallbacks Choreographer.java:761
android.view.Choreographer.doFrame Choreographer.java:693
android.view.Choreographer$FrameDisplayEventReceiver.run Choreographer.java:935
android.os.Handler.handleCallback Handler.java:873
android.os.Handler.dispatchMessage Handler.java:99
android.os.Looper.loop Looper.java:193
android.app.ActivityThread.main ActivityThread.java:6912
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:493
com.android.internal.os.ZygoteInit.main ZygoteInit.java:860

TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType)
Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type)
Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer)
Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer)
Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer)
View.n_Invalidate (System.IntPtr jnienv, System.IntPtr native__this)
(wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.48(intptr,intptr)

TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer)
TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType)

Basic Information

<PackageReference Include="Xamarin.Forms" Version="4.5.0.495" />
  • Affected Devices:
    motorola one - Android 9

I'm open to apply any change to project that might help you to discover more about this error. I know at this time, we've not enough information.

imagebutton 6 high Android bug

All 15 comments

@ysmoradi can you post the XAML you are using that contains the image button?

@ysmoradi can you post the XAML you are using that contains the image button?

Sure, first of all, I should find a page that contains that ImageButton and it takes some time.
This crash is not happening all the time.

This is my plan: App center can detect if previous session was crashed or not. I write every page's name I navigate to preferences, so the next time I get crash report, I can see the location.

Please attach a zipped reproduction. Thanks.

I need more time, I'm gonna publish a new version of app which logs everywhere I go in the application. After the app gets crashed again, I'll detect it using AppCenter's Crash SDK, then I'll add more info to that Crash Report and resubmit that again to the app center, so I can get more insights about my crashes.

@ysmoradi Thanks, we'll wait to hear from you.

@ysmoradi Thanks, we'll wait to hear from you.

I've configured firebase crash reporter and I'm gonna hunt it soon

@ysmoradi Great!! Thanks!

Assume that we've 2 versions of the app:
V1: AppCenter Crashes is configured + we log the name of every page on open, so we can detect in which page crash has happened in the next session of our app. Note that there is a method in AppCenter Sdk which returns true if the previous session was crashed.
V2: Replaced AppCenter with firebase crashlytics + Updated XF and Rg.Plugins.Popup nuget packages

We're receiving crash reports which are identical to the one that I've submitted already in V1 of our apps. Surprisingly there is no crash report for V2!

These are changes we made before releasing the new version (2):
1- We updated from Rg.Plugins.Popup 1.1.5.188 to 2.0.0.2
Although there is no such issue in Rg.Plugins.Popup, but they've fixed several issues including crashes in the new version. The new version is also using AndroidX as like as XF 4.5 on Android 10 SDK which is being used in our app.
2- In our new version of our app, we clear rg.plugins.popup "popup stack" when we decide to clear "xf nav stack". Previously we were clearing xf nav stack only.
3- We updated from XF 4.5.0.495 to 4.5.0.530

In the end, the severity of this issue is low for us at the moment, because it seems it's gone for some reason!

But I'd like to share some notes for other people who might experience this issue

1- We're using ImageButton with a global style that sets the background color to transparent by default.
2- Sometimes we toggle IsVisible based on requirements.
3- We're using Embedded png images with GlideX handler.
4- In following video, it shows how easy was for the app to gets crashed! A customer opens the app, then he starts scrolling on ListView (Not CollectionView) and in the middle of scrolling, it hangs and then crashes. The customer's device is android 5 with weak hardware.
I'm not sure if it helps you to provide a XAML file of that view or not, but I'm open to do that.

2020-03-29-22-55-12-mOz25ioW-qdQ

We've invested a lot in our logging mechanisms recently, so for the next crashes in our app, I'll submit an issue with lots of details!

@ysmoradi What version of Xamarin.Forms did you update to? Perhaps the issue was fixed there. Thanks for the analysis!!

@ysmoradi on the ListView are you using recycling or retain? If you're using recycling does the bug still happen with retain?

The issue here is that there's a delayed animate call from native android which tries to call into our managed peer because of this override

https://github.com/xamarin/Xamarin.Forms/blob/954cc8b0f174f179fd3395b4b1f257201f9701af/Xamarin.Forms.Platform.Android/AppCompat/ImageButtonRenderer.cs#L121

If we can get rid of that override (like we did with Label) it will fix this error

Just not sure how to achieve the result of what that override is doing without using the override :-/ need to dig around in the android source see if there's a different way

@ysmoradi What version of Xamarin.Forms did you update to? Perhaps the issue was fixed there. Thanks for the analysis!!

You're welcome
We're using 4.5.0.530

@ysmoradi on the ListView are you using recycling or retain? If you're using recycling does the bug still happen with retain?

We're using ListViewCachingStrategy.RecycleElement
Note that this is not happening anymore as I said.

@PureWeen If I swap out the usage of the ImageButton with an Image (with TapGestureRecognizer), will that prevent this issue from occurring, because I am not using the ImageButton any longer?

Was this page helpful?
0 / 5 - 0 ratings