xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.87k forks source link

[Bug] Random android crash: EXCEPTION: Cannot access a disposed object. Object name: 'Xamarin.Forms.Platform.Android.ScrollViewRenderer'. #15733

Closed Pradeepgodaraitron closed 1 year ago

Pradeepgodaraitron commented 1 year ago

Description : i am facing android app crash when moving from one page to another using button click action after click on button getting app crash.

Steps to Reproduce

app crash is not consistent
Call Stack EXCEPTION: Cannot access a disposed object. Object name: 'Xamarin.Forms.Platform.Android.ScrollViewRenderer'. STACK TRACE: at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in :0 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in :0 at Android.Views.View.Measure (System.Int32 widthMeasureSpec, System.Int32 heightMeasureSpec) [0x00035] in <8638e88f61db46e4bc35e66b77e3b3e8>:0 at Xamarin.Forms.Platform.Android.VisualElementTracker.UpdateLayout () [0x000da] in <9a109ed09ba344b88476362cfdc421a5>:0 at Xamarin.Forms.Platform.Android.ScrollViewRenderer.UpdateLayout () [0x0000a] in <9a109ed09ba344b88476362cfdc421a5>:0 at Xamarin.Forms.Platform.Android.ScrollViewRenderer.HandleLayoutChanged (System.Object sender, System.EventArgs e) [0x00000] in <9a109ed09ba344b88476362cfdc421a5>:0 at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x0019e] in <0c78caada6294b6391bfbb908a3e4681>:0 at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in <0c78caada6294b6391bfbb908a3e4681>:0 at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in <0c78caada6294b6391bfbb908a3e4681>:0 at Xamarin.Forms.Layout.ResolveLayoutChanges () [0x0005c] in <0c78caada6294b6391bfbb908a3e4681>:0 at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <8638e88f61db46e4bc35e66b77e3b3e8>:0 at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <8638e88f61db46e4bc35e66b77e3b3e8>:0 at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V (_JniMarshal_PP_V callback, System.IntPtr jnienv, System.IntPtr klazz) [0x00005] in <8638e88f61db46e4bc35e66b77e3b3e8>:0

Expected Behavior

Actual Behavior

Basic Information

Version with issue: Xamarin.Forms 4.8 IDE: VS 2019 Platform Target Frameworks: Android: 10

Workaround :not yet

jfversluis commented 1 year ago

Duplicate of #15404

miz-online commented 1 year ago

Hi,

this is not the same issue, please check the call stack. There are lots of Object Disposed exceptions in Android renderers. Most of them occur when leaving a certain view too fast (e.g. clicking through views which are shown briefly and then discarded, or that are updated and discarded while the update is in progress).

Normally we work around by deriving our own renderer and wrapping base calls into try/catch to filter out disposed exceptions (the views get disposed, so what do we care about object disposed exceptions?) but in this case, unfortunately there are no virtual methods in between and we cannot replace the renderers completely as it uses many internal classes :-(

it would be good if you can fix this, e.g by ignoring the exception in the event handler

thanks mz

PS. from my point of view throwing object disposed exceptions in renderers is a bad idea from the start because you can't control how fast users click through you app, so views can get disposed before they are completely initialized - that's the main occurrence of those exceptions. it would be very nice to have an opt-in to ignore the exceptions before they are marshalled to the java part and crash the app