Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Android] Xamarin caused by: android.runtime.JavaProxyThrowable: System.ObjectDisposedException: Cannot access a disposed object. #2004

Closed
duzenko opened this issue Mar 2, 2018 · 66 comments

Comments

@duzenko
Copy link

duzenko commented Mar 2, 2018

Description

This error occurs when navigating between pages with complex-row listviews. Since no user code is involved it's not possible to catch and handle the exception.

Steps to Reproduce

Intermittent.

Expected Behavior

Navigating pages does not cause crashes.

Actual Behavior

A crash occurs once in a while.

Basic Information

  • Version with issue: 2.5 280
  • Last known good version: N/A
  • IDE: VS2017 Community
  • Platform Target Frameworks:
    • Android: 8.0
  • Android Support Library Version: 26.1.0.1

Reproduction

https://github.com/xamarin/Xamarin.Forms/files/2197967/disp2.zip

Exception happens here

image

Stack trace

Xamarin caused by: android.runtime.JavaProxyThrowable: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Android.Graphics.Bitmap'.
  at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <e8c0e16a54534fa885244f0ad837c79e>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualInt32Method (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <e8c0e16a54534fa885244f0ad837c79e>:0 
  at Android.Graphics.Bitmap.get_Height () [0x0000a] in <848bbd7c681a4975918c72f17d2f5144>:0 
  at Xamarin.Forms.Platform.Android.ButtonDrawable.Draw (Android.Graphics.Canvas canvas) [0x00021] in D:\agent_work\1\s\Xamarin.Forms.Platform.Android\Renderers\ButtonDrawable.cs:55 
  at Android.Graphics.Drawables.Drawable.n_Draw_Landroid_graphics_Canvas_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_canvas) [0x0000f] in <848bbd7c681a4975918c72f17d2f5144>:0 
  at (wrapper dynamic-method) System.Object:224a5ebe-c56f-4264-ad89-b784cc0da834 (intptr,intptr,intptr)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.ButtonDrawable.n_draw(Native Method)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.ButtonDrawable.draw(ButtonDrawable.java:50)
	at android.graphics.drawable.RippleDrawable.drawContent(RippleDrawable.java:836)
	at android.graphics.drawable.RippleDrawable.draw(RippleDrawable.java:692)
	at android.view.View.getDrawableRenderNode(View.java:18643)
	at android.view.View.drawBackground(View.java:18579)
	at android.view.View.draw(View.java:18367)
	at android.view.View.updateDisplayListIfDirty(View.java:17354)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.draw(View.java:18379)
	at android.view.View.updateDisplayListIfDirty(View.java:17354)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.widget.ListView.drawChild(ListView.java:3761)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.widget.AbsListView.dispatchDraw(AbsListView.java:3551)
	at android.widget.ListView.dispatchDraw(ListView.java:3744)
	at android.view.View.draw(View.java:18379)
	at android.widget.AbsListView.draw(AbsListView.java:7199)
	at android.view.View.updateDisplayListIfDirty(View.java:17354)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.draw(View.java:18379)
	at android.view.View.updateDisplayListIfDirty(View.java:17354)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.draw(View.java:18379)
	at android.view.View.updateDisplayListIfDirty(View.java:17354)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1366)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.draw(View.java:18379)
	at android.view.View.updateDisplayListIfDirty(View.java:17354)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.updateDisplayListIfDirty(View.java:17349)
	at android.view.View.draw(View.java:18138)
	at android.view.ViewGroup.drawChild(ViewGroup.java:3969)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3755)
	at android.view.View.draw(View.java:18379)
	at com.android.internal.policy.DecorView.draw(DecorView.java:940)
	at android.view.View.updateDisplayListIfDirty(View.java:17354)
	at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:692)
	at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:698)
	at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:806)
	at android.view.ViewRootImpl.draw(ViewRootImpl.java:3136)
	at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2932)
	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2520)
	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1519)
	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7113)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
	at android.view.Choreographer.doCallbacks(Choreographer.java:702)
	at android.view.Choreographer.doFrame(Choreographer.java:638)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
	at android.os.Handler.handleCallback(Handler.java:751)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at android.os.Looper.loop(Looper.java:154)
	at android.app.ActivityThread.main(ActivityThread.java:6780)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
@pauldipietro pauldipietro added this to New in Triage Mar 2, 2018
@kingces95 kingces95 added s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. p/Android labels Mar 2, 2018
@kingces95
Copy link
Contributor

Please provide a reproduction.

@kingces95 kingces95 moved this from New to Needs Info in Triage Mar 2, 2018
@duzenko
Copy link
Author

duzenko commented Mar 12, 2018

I can't make our production build to fail every time. Usually it happens every time at the start of the day but when I try to repeat it in a test app it stops happening on a device in production build as well.

@duzenko
Copy link
Author

duzenko commented Mar 12, 2018

@duzenko
Copy link
Author

duzenko commented Mar 14, 2018

@kingces95
How can I send you the source code of our app? It's closed source and I can't just attach it to this ticket.
I can repeat it now all the time on a device (but not on an emulator).

@duzenko
Copy link
Author

duzenko commented Mar 16, 2018

xp.zip
Repro case.
Steps:

  1. Using the drawer menu go to Address List
  2. Click on the last row (scroll to bottom if necessary). A details screen opens.
  3. Go back to the Address list.
  4. Using the drawer menu go to My Associations.
  5. Repeat from step 1.
    It takes a few loops but sooner or later it crashes on step 3 with an ObjectDisposedException
    Tested on Samsung Tab S2 (Android 7) and LG Flex2 (Android 6). Emulator with Android 7.0 - same crash.

@pauldipietro
Copy link
Contributor

Took about 10 iterations on an 8.0 emulator to crash.

@pauldipietro pauldipietro moved this from Needs Info to Ready For Work in Triage Mar 23, 2018
@samhouts samhouts added i/critical and removed s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. labels Apr 17, 2018
@ryanherman
Copy link

I started seeing this in Xamarin.Forms 3.0 and 3.1 Pre

JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Android.Graphics.Bitmap'.
JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
JniPeerMembers+JniInstanceMethods.InvokeAbstractVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
Bitmap.Recycle ()
ButtonDrawable.Reset ()
ButtonDrawable.Dispose (System.Boolean disposing)
Object.Dispose ()
ButtonBackgroundTracker.Dispose (System.Boolean disposing)
ButtonBackgroundTracker.Dispose ()
ButtonRenderer.Dispose (System.Boolean disposing)
Object.Dispose ()
VisualElementRenderer`1[TElement].Dispose (System.Boolean disposing)
Object.Dispose ()
ListViewRenderer.ClearRenderer (Android.Views.View renderedView)
ListViewRenderer.Dispose (System.Boolean disposing)
Object.Dispose ()
VisualElementRenderer`1[TElement].Dispose (System.Boolean disposing)
Object.Dispose ()
VisualElementRenderer`1[TElement].Dispose (System.Boolean disposing)
Object.Dispose ()
VisualElementRenderer`1[TElement].Dispose (System.Boolean disposing)
PageRenderer.Dispose (System.Boolean disposing)
Object.Dispose ()
FragmentContainer.OnDestroyView ()
Fragment.n_OnDestroyView (System.IntPtr jnienv, System.IntPtr native__this)
(wrapper dynamic-method) System.Object.7749783a-08da-40f9-a1ba-680c166f64ec(intptr,intptr)

@MatthewGerber
Copy link

Same...been getting many of these in the App Center error dashboard. Not exactly sure how to reproduce reliably.

@samih7
Copy link

samih7 commented May 16, 2018

Same issue here. It occurs (not consistently) when navigating towards a new instance of a page containing a ListView with custom ViewCells. Page was previously removed from the navigation stack in my case.

  1. Creating "Page X" with ListView - ListView is filtered, changed a little bit;
  2. "Page X" is removed from the navigation Stack;
  3. New instance of "Page X" is created => crash when navigating to "Page X"

@MatthewGerber
Copy link

MatthewGerber commented May 16, 2018 via email

@samih7
Copy link

samih7 commented May 16, 2018

I reproduced the issue by manually triggering a garbage collection (GC.Collect();) after ListView's ItemSource was set & I might have solved it (to be confirmed as it was intermittent) by calling GC.Collect(); first thing when I get on the page (ViewModel constructor in my case).

  • Maybe a garbage collection is periodically done at a "wrong time" and this behavior is avoided by manually doing it ?

Does it work for you ?

@balaameex
Copy link

I am also struck with the same crash, Please let me know if any solution

JniPeerMembers.AssertSelf
android.runtime.JavaProxyThrowable: System.ObjectDisposedException: Cannot access a disposed object.

Xamarin caused by: android.runtime.JavaProxyThrowable: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Android.Graphics.Bitmap'.
Java.Interop.JniPeerMembers.AssertSelf(IJavaPeerable self)<7bd6e23e74244e9191c46983d3bb2eeb>:0
Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeAbstractVoidMethod(string encodedMember, IJavaPeerable self, JniArgumentValue* parameters)<7bd6e23e74244e9191c46983d3bb2eeb>:0
Android.Graphics.Bitmap.Recycle()<82958282c7e341b985c12639e88fc1d1>:0
Xamarin.Forms.Platform.Android.ButtonDrawable.Reset()<173f39d71f0d4d928f5bbea42e96ffa8>:0
Xamarin.Forms.Platform.Android.ButtonDrawable.Dispose(bool disposing)<173f39d71f0d4d928f5bbea42e96ffa8>:0
Java.Lang.Object.Dispose()<82958282c7e341b985c12639e88fc1d1>:0
Xamarin.Forms.Platform.Android.ButtonBackgroundTracker.Dispose(bool disposing)<173f39d71f0d4d928f5bbea42e96ffa8>:0
Xamarin.Forms.Platform.Android.ButtonBackgroundTracker.Dispose()<173f39d71f0d4d928f5bbea42e96ffa8>:0
Xamarin.Forms.Platform.Android.ButtonRenderer.Dispose(bool disposing)<173f39d71f0d4d928f5bbea42e96ffa8>:0
Java.Lang.Object.Dispose()<82958282c7e341b985c12639e88fc1d1>:0
Xamarin.Forms.Platform.Android.VisualElementRenderer.Dispose(bool disposing)<173f39d71f0d4d928f5bbea42e96ffa8>:0
Xamarin.Forms.Platform.Android.PageRenderer.Dispose(bool disposing)<173f39d71f0d4d928f5bbea42e96ffa8>:0
Java.Lang.Object.Dispose()<82958282c7e341b985c12639e88fc1d1>:0
Xamarin.Forms.Platform.Android.AppCompat.FragmentContainer.OnDestroyView()<173f39d71f0d4d928f5bbea42e96ffa8>:0
Android.Support.V4.App.Fragment.n_OnDestroyView(IntPtr jnienv, IntPtr native__this)<40bb5a57295c4f648daa62e9e7aa774b>:0
at (wrapper dynamic-method) System.Object.84698d0a-0c20-40fc-87af-f3c645d9eec0(intptr,intptr)
md58432a647068b097f9637064b8985a5e0.FragmentContainer.n_onDestroyView(Native Method)
md58432a647068b097f9637064b8985a5e0.FragmentContainer.onDestroyView()FragmentContainer.java:59
android.support.v4.app.Fragment.performDestroyView()Fragment.java:2590
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1503
android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState()FragmentManager.java:1740
android.support.v4.app.BackStackRecord.executeOps()BackStackRecord.java:794
android.support.v4.app.FragmentManagerImpl.executeOps()FragmentManager.java:2580
android.support.v4.app.FragmentManagerImpl.executeOpsTogether()FragmentManager.java:2367
android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute()FragmentManager.java:2322
android.support.v4.app.FragmentManagerImpl.execPendingActions()FragmentManager.java:2229
android.support.v4.app.FragmentManagerImpl$1.run()FragmentManager.java:700
android.os.Handler.handleCallback()Handler.java:739
android.os.Handler.dispatchMessage()Handler.java:95
android.os.Looper.loop()Looper.java:168
android.app.ActivityThread.main()ActivityThread.java:5845
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:797
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:687

@louis030195
Copy link

Only happen on Android (tested on Samsung Galaxy S6 - Android 7.0), sometimes after 2 min, sometimes running for hours without crash.
I'm not using ListView, thought it was linked to OnPropertyChanged not running on UI thread so i tried :

#if __ANDROID__
            if (Android.OS.Looper.MyLooper() != null && Android.OS.Looper.MyLooper().Thread == Android.OS.Looper.MainLooper.Thread)
            {
                changed.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
            else
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    changed.Invoke(this, new PropertyChangedEventArgs(propertyName));
                });
            }
#endif

but even making it run on UI thread doesn't fix the issue.

Unhandled Exception:
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Xamarin.Forms.Platform.Android.FormsTextView'.
  at (wrapper dynamic-method) System.Object:a3b623bc-af3e-44cb-ae90-81e9b2c34eb0 (intptr,intptr)
[ERROR] FATAL UNHANDLED EXCEPTION: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Xamarin.Forms.Platform.Android.FormsTextView'.
  at (wrapper dynamic-method) System.Object:a3b623bc-af3e-44cb-ae90-81e9b2c34eb0 (intptr,intptr)


05-28 14:06:36.211	Samsung SM-G920F	Error	23539	AndroidRuntime	Object name: 'Xamarin.Forms.Platform.Android.FormsTextView'.
  at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <e8c0e16a54534fa885244f0ad837c79e>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <e8c0e16a54534fa885244f0ad837c79e>:0 
  at Android.Widget.TextView.set_TextFormatted (Java.Lang.ICharSequence value) [0x00029] in <848bbd7c681a4975918c72f17d2f5144>:0 
  at Android.Widget.TextView.set_Text (System.String value) [0x0000d] in <848bbd7c681a4975918c72f17d2f5144>:0 
  at Xamarin.Forms.Platform.Android.LabelRenderer.UpdateText () [0x00098] in <aae4e9ce5a5b4d3eaec4edf21079f3fa>:0 
  at Xamarin.Forms.Platform.Android.LabelRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x000c5] in <aae4e9ce5a5b4d3eaec4edf21079f3fa>:0 
  at (wrapper delegate-invoke) <Module>:invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
  at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00012] in <1aabc0fecdaa41b6a5c04760c77bb648>:0 
  at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in <1aabc0fecdaa41b6a5c04760c77bb648>:0 
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x0010e] in <1aabc0fecdaa41b6a5c04760c77bb648>:0
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0015b] in <1aabc0fecdaa41b6a5c04760c77bb648>:0 
  at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x001f9] in <1aabc0fecdaa41b6a5c04760c77bb648>:0 
  at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in <1aabc0fecdaa41b6a5c04760c77bb648>:0 
  at Xamarin.Forms.BindingExpression+BindingExpressionPart.<PropertyChanged>b__47_0 () [0x00000] in <1aabc0fecdaa41b6a5c04760c77bb648>:0 
  at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <848bbd7c681a4975918c72f17d2f5144>:0 
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <848bbd7c681a4975918c72f17d2f5144>:0 
  at (wrapper dynamic-method) System.Object:c9b101f5-2323-49dd-9e53-f56cac4b4160 (intptr,intptr)
	at mono.java.lang.RunnableImplementor.n_run(Native Method)
	at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
	at android.os.Handler.handleCallback(Handler.java:751)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at android.os.Looper.loop(Looper.java:154)
	at android.app.ActivityThread.main(ActivityThread.java:6682)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

@rmarinho
Copy link
Member

I m having troubles to reproduce this with the sample attached. Anyone with a better and reliable reproduction ?

@Aquastorm
Copy link

@rmarinho and @PureWeen
About the topic which devices and APIs are affected, here below is some data taken from App Center.

Total impacted users over the last month: 27
It's not a big number of users, but typically users affected by crashes uninstall our app and/or write bad reviews on the stores.. and that hurts.

Most Affected Device

Device Percentage
Galaxy S8 40.0%
Galaxy S7 edge 20.0%
P10 13.3%
Galaxy S9+ 13.3%
Others 13.3%

Most affected API

API Percentage
26 51.9%
24 33.3%
23 11.1%
22 3.7%

Affected OS Android versions are starting from 5.1.1 till 8.0.0. Actually every version we support (5.x, 6.x, 7.x and 8.x) is impacted.

Impacted devices: Huawei P10, Huawei P10 lite, Huawei Honor 5C, Samsung Galaxy S6 to S9 (including + and edge versions), Samsung Galaxy A5, Wiko Jerry 2, HTC U Play, Fairphone FP2, Sony Xperia Z5.

We update Xamarin.Forms and the related NuGet packages regularly (only stable channel). Now we are using:
Xamarin.Forms v. 3.1.0.697729
Xamarin.Android.Support.x v. 27.0.2.1

Visual Studio 2017 is always up-to-date (i.e. at the time of writing 15.7.6).

@duzenko
Copy link
Author

duzenko commented Aug 6, 2018

What it's hurting even more is my reputation with the customer.
During the months of Xamarin doing nothing about this bug (and closing it for no reason on Jun 28) our app crashed a number of times in the customer's hands doing basic stuff, like navigating pages or taking a photo. The customer now sees me, as programmer, as a weak link in their software department. It would take me days to track the crash logs on hockeyapp to this bug. I have reported 10 xamarin bugs this year alone, not mentioning suffering from the bugs reported by others. Every time I say "It's Xamarin bug, I reported it to them, but it's been N months and no answer" it's just making me look worse in their eyes.
Thanks a lot, Xamarin!

@PureWeen
Copy link
Contributor

PureWeen commented Aug 6, 2018

Here's the nuget package from the PR

Xamarin.Forms.3.3.0.726028.zip

If anyone wants to test

I've ran this through what reproduction cases I have and I'm not seeing the exception anymore. It should be available on the nightly feed this week as well if you want to wait for that.

@RedasP
Copy link

RedasP commented Aug 8, 2018

@duzenko Did the PureWeen's NuGet package fix the issue for you?

After the update, I still get the following exception:

Unhandled Exception:

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Android.Graphics.Bitmap'.

08-08 08:40:08.082 D/Mono    (18751): DllImport attempting to load: '/system/lib/liblog.so'.[0:] ===> ERROR (AndroidEnvironment_UnhandledExceptionRaiser, 157): System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Android.Graphics.Bitmap'.
  at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <7802aa64ad574c33adca332a3fa9706a>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualInt32Method (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <7802aa64ad574c33adca332a3fa9706a>:0 
  at Android.Graphics.Bitmap.get_Height () [0x0000a] in <263adecfa58f4c449f1ff56156d886fd>:0 
  at Xamarin.Forms.Platform.Android.ButtonDrawable.Draw (Android.Graphics.Canvas canvas) [0x00021] in D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ButtonDrawable.cs:66 
  at Android.Graphics.Drawables.Drawable.n_Draw_Landroid_graphics_Canvas_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_canvas) [0x0000f] in <263adecfa58f4c449f1ff56156d886fd>:0 
  at (wrapper dynamic-method) System.Object.8a38ea5e-9428-4c53-ab85-cd8fb72a22d6(intptr,intptr,intptr) (...\MainActivityAppCompat.cs)

08-08 08:40:08.085 D/Mono    (18751): DllImport loaded library '/system/lib/liblog.so'.
08-08 08:40:08.085 D/Mono    (18751): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
08-08 08:40:08.085 D/Mono    (18751): Searching for '__android_log_print'.
08-08 08:40:08.085 D/Mono    (18751): Probing '__android_log_print'.
08-08 08:40:08.085 D/Mono    (18751): Found as '__android_log_print'.
08-08 08:40:08.089 I/MonoDroid(18751): UNHANDLED EXCEPTION:
08-08 08:40:08.122 I/MonoDroid(18751): System.ObjectDisposedException: Cannot access a disposed object.
08-08 08:40:08.122 I/MonoDroid(18751): Object name: 'Android.Graphics.Bitmap'.
08-08 08:40:08.122 I/MonoDroid(18751):   at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <7802aa64ad574c33adca332a3fa9706a>:0 
08-08 08:40:08.122 I/MonoDroid(18751):   at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualInt32Method (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <7802aa64ad574c33adca332a3fa9706a>:0 
08-08 08:40:08.122 I/MonoDroid(18751):   at Android.Graphics.Bitmap.get_Height () [0x0000a] in <263adecfa58f4c449f1ff56156d886fd>:0 
08-08 08:40:08.122 I/MonoDroid(18751):   at Xamarin.Forms.Platform.Android.ButtonDrawable.Draw (Android.Graphics.Canvas canvas) [0x00021] in D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ButtonDrawable.cs:66 
08-08 08:40:08.122 I/MonoDroid(18751):   at Android.Graphics.Drawables.Drawable.n_Draw_Landroid_graphics_Canvas_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_canvas) [0x0000f] in <263adecfa58f4c449f1ff56156d886fd>:0 
08-08 08:40:08.122 I/MonoDroid(18751):   at (wrapper dynamic-method) System.Object.8a38ea5e-9428-4c53-ab85-cd8fb72a22d6(intptr,intptr,intptr)
08-08 08:40:08.240 W/zygote  (18751): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
08-08 08:40:08.263 D/Mono    (18751): DllImport searching in: '__Internal' ('(null)').
08-08 08:40:08.263 D/Mono    (18751): Searching for 'java_interop_jnienv_throw'.
08-08 08:40:08.263 D/Mono    (18751): Probing 'java_interop_jnienv_throw'.
08-08 08:40:08.263 D/Mono    (18751): Found as 'java_interop_jnienv_throw'.
An unhandled exception occured.

Encountered EGL error 12289 EGL_NOT_INITIALIZED during rendering08-08 08:40:14.910 E/mono    (18751): 

08-08 08:40:14.910 E/mono    (18751): Unhandled Exception:
08-08 08:40:14.910 E/mono    (18751): System.ObjectDisposedException: Cannot access a disposed object.
08-08 08:40:14.910 E/mono    (18751): Object name: 'Android.Graphics.Bitmap'.
08-08 08:40:14.910 E/mono    (18751):   at (wrapper dynamic-method) System.Object.8a38ea5e-9428-4c53-ab85-cd8fb72a22d6(intptr,intptr,intptr)
08-08 08:40:14.910 E/mono-rt (18751): [ERROR] FATAL UNHANDLED EXCEPTION: System.ObjectDisposedException: Cannot access a disposed object.
08-08 08:40:14.910 E/mono-rt (18751): Object name: 'Android.Graphics.Bitmap'.
08-08 08:40:14.910 E/mono-rt (18751):   at (wrapper dynamic-method) System.Object.8a38ea5e-9428-4c53-ab85-cd8fb72a22d6(intptr,intptr,intptr)
08-08 08:40:14.914 D/        (18751): HostConnection::get() New Host Connection established 0x8cf0a800, tid 18751
08-08 08:40:14.951 E/EGL_emulation(18751): tid 18785: eglSwapBuffers(1809): error 0x3001 (EGL_NOT_INITIALIZED)
08-08 08:40:14.952 F/OpenGLRenderer(18751): Encountered EGL error 12289 EGL_NOT_INITIALIZED during rendering
08-08 08:40:14.952 F/libc    (18751): Fatal signal 6 (SIGABRT), code -6 in tid 18785 (RenderThread), pid 18751 (ry.) 

@duzenko
Copy link
Author

duzenko commented Aug 8, 2018

I will test it when released publicly.

@PureWeen
Copy link
Contributor

PureWeen commented Aug 8, 2018

@RedasP

When testing can you delete your bin/obj and also uninstall the app from the device you are testing?

If you are testing the nuget package I attached?

Looking at your exception the line numbers look to correspond with a previous version and not the nuget.

When I tested the nuget that's what I had to do to ensure it was using the latest and greatest. If you are still having issues is there a repro you could possibly give me?

@RedasP
Copy link

RedasP commented Aug 8, 2018

@PureWeen It does work now after I try your suggestion. Thank you. 👍

@PureWeen
Copy link
Contributor

PureWeen commented Aug 8, 2018

@RedasP
That's great to hear!

On a side note the core cause of this looks to be from a bug with the Mono GC.
We're putting together an issue for the Mono team and I'll link to that once it's created

@PureWeen
Copy link
Contributor

PureWeen commented Aug 8, 2018

xamarin/xamarin-android#2049

One part to take note of as workaround

To solve the problem, add an environment.txt to the project with a build action of AndroidEnvironment:

MONO_GC_PARAMS=bridge-implementation=old
Using the old GC implementation, the crash doesn't occur!

@Aquastorm
Copy link

Thank you for going forward with this issue

@cramirez070506
Copy link

cramirez070506 commented Aug 19, 2018

Adding [CachingStrategy="RecycleElement"] to your listview might help solve the issue.

<ListView ItemsSource="{Binding Items}" CachingStrategy="RecycleElement"
ItemTemplate="{StaticResource xxx}" HasUnevenRows="true"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="fuchsia" >

and avoid setting your ItemSource to null just clear() it.

@Aquastorm
Copy link

@cramirez070506 CachingStrategy="RecycleElement" doesn't help preventing the issue

@NPadrutt
Copy link

@PureWeen we had this issue despite having added the environment.txt as you described it. unless we did something wrong.

@PureWeen
Copy link
Contributor

@NPadrutt can you try https://www.nuget.org/packages/Xamarin.Forms/3.2.0.729530-pre2
if you still see the error can you paste a stack trace?

@NPadrutt
Copy link

We had to create some nasty work arounds to get the software out the door. But I will try it out once we refactored the code.

@PureWeen
Copy link
Contributor

@NPadrutt Alright. If you happen to have any stack traces laying around of the exception you were seeing that would be helpful :-) The problem is that this exception is basically the same as getting an NRE so it's hard to say whether your particular instance is related to this or not

@NPadrutt
Copy link

mh, I see. I'll let you know when I know more :)

@AntRemo
Copy link

AntRemo commented Aug 27, 2018

@PureWeen

Preliminary tests of 3.2.0.729530-pre2 appear to have fixed this issue for my scenario!!! 😃

Many thanks and looking forward to GA. 👍

@samhouts samhouts removed this from the 3.2.0 milestone Sep 12, 2018
@ehuna
Copy link

ehuna commented Sep 16, 2018

We are also seeing many of these in App Center and users are reporting crashes, so I thought I'd add a stacktrace..

The stacktrace contains Xamarin.Forms.BindableProperty references - and I see no trace of our code. Not sure if this is the same scenario that is mentioned as fixed in 3.2.0.729530-pre2 (?)

JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Android.Graphics.Bitmap'.

JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
JniPeerMembers+JniInstanceMethods.InvokeAbstractVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
Bitmap.Recycle ()
ButtonDrawable.Reset ()
ButtonBackgroundTracker.Reset ()
ButtonBackgroundTracker.ButtonPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e)
(wrapper delegate-invoke) .invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
BindableObject.OnPropertyChanged (System.String propertyName)
Element.OnPropertyChanged (System.String propertyName)
BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent)
BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes)
BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess)
BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value)
Button.BorderRadiusPropertyChanged (Xamarin.Forms.BindableObject bindable, System.Object oldvalue, System.Object newvalue)
BindableObject.ClearValue (Xamarin.Forms.BindableProperty property, System.Boolean fromStyle, System.Boolean checkAccess)
BindableObject.ClearValue (Xamarin.Forms.BindableProperty property)
Setter.UnApply (Xamarin.Forms.BindableObject target, System.Boolean fromStyle)
Style.UnApplyCore (Xamarin.Forms.BindableObject bindable, Xamarin.Forms.Style basedOn)
IStyle.UnApply (Xamarin.Forms.BindableObject bindable)
VisualElement+MergedStyle.SetStyle (Xamarin.Forms.IStyle implicitStyle, System.Collections.Generic.IList`1[T] classStyles, Xamarin.Forms.IStyle style)
VisualElement+MergedStyle.set_Style (Xamarin.Forms.IStyle value)
<.cctor>b__240_6 (Xamarin.Forms.BindableObject bindable, System.Object oldvalue, System.Object newvalue)
BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent)
BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes)
BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget)
BindingExpression.Apply (System.Boolean fromTarget)
BindingExpression+BindingExpressionPart.b__49_0 ()
Thread+RunnableImplementor.Run ()
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
(wrapper dynamic-method) System.Object.8618d31c-c109-49dc-a54d-404ffc85a5ed(intptr,intptr)

@PureWeen
Copy link
Contributor

@ehuna that does look like the same issue. That stack trace looks like a cleanup operation that usually gets queue'd up so the trace doesn't link back to your code. If the Mono GC bug didn't exist then the code here would just properly cleanup the resource and be on its way.

@RedasP
Copy link

RedasP commented Sep 22, 2018

Does this look like the same issue?

I got this exception when clicking on a list item which opens a new page, then going back to the list view page and scanning an item which triggers a search and looks like AutoCompleteRenderer (base type SearchBarRenderer) is disposed.

If I simply scan from the list view page without going to the list item page and back again, it works fine.

System.ObjectDisposedException: Cannot access a disposed object.
Object name: '*.Droid.CustomRenderer.AutoCompleteRenderer'.
  at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <e4b4fbb0c9154793acaae753fd1b4e27>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <e4b4fbb0c9154793acaae753fd1b4e27>:0 
  at Android.Views.View.get_Context () [0x0000a] in <c27f5eedfc1a439c9ab4935b10674f11>:0 
  at *.Droid.CustomRenderer.AutoCompleteRenderer+<>c__DisplayClass4_0.<OnElementChanged>b__0 (System.Object o, System.Object obj) [0x00000] in <acbe393a4dc3408295781bf203d9426a>:0 
  at (wrapper delegate-invoke) System.EventHandler`1[System.Object].invoke_void_object_TEventArgs(object,object)
  at *.Base.CustomControls.AutoComplete.FireSelectedItemChanged (System.Object obj) [0x00000] in <143ea12b205e435f9ed4239b70688424>:0 
  at *.Base.Views.SearchItem+<>c__DisplayClass21_1.<OnScannerDataReceived>b__1 () [0x00000] in <143ea12b205e435f9ed4239b70688424>:0 
  at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <c27f5eedfc1a439c9ab4935b10674f11>:0 
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <c27f5eedfc1a439c9ab4935b10674f11>:0 
  at (wrapper dynamic-method) System.Object.41(intptr,intptr)

@PureWeen
Copy link
Contributor

@RedasP your exception looks different. AutoCompleteRenderer isn't something that's part of the core framework so it's hard to say what's causing your exception. It looks like the custom AutoCompleteRenderer is holding onto something it shouldn't be.

If you can create a reproduction and create an issue we can look at it to see if there's an error on our side or not

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Sprint 137
  
To do
Sprint 139
  
Done
v3.2.0
  
Done
Development

No branches or pull requests