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.
Intermittent.
Navigating pages does not cause crashes.
A crash occurs once in a while.
https://github.com/xamarin/Xamarin.Forms/files/2197967/disp2.zip
Exception happens here
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)
Please provide a reproduction.
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.
@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).
xp.zip
Repro case.
Steps:
Took about 10 iterations on an 8.0 emulator to crash.
I started seeing this in Xamarin.Forms 3.0 and 3.1 Pre
Stack Trace
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)
Same...been getting many of these in the App Center error dashboard. Not exactly sure how to reproduce reliably.
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.
This is exactly my setup, too.
On Wed, May 16, 2018, 4:06 AM Samih Alkeilani notifications@github.com
wrote:
Same issue here. It occurs (not consistently) when navigating towards a
new instance of a page (containing a ListView with custom ViewCells) that
was already instantiated at least once. Page was previously removed from
the navigation stack in my case.
- Creating "Page X" with ListView - ListView is filtered, changed a
little bit;- "Page X" is removed from the navigation Stack;
- New instance of "Page X" is created => crash when navigating to
"Page X"—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/xamarin/Xamarin.Forms/issues/2004#issuecomment-389432174,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AEbY-r6bKZYHYsqKR8DStkZO4cLc6NLCks5ty93_gaJpZM4SZ0sv
.
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_).
Does it work for you ?
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
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
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)
I m having troubles to reproduce this with the sample attached. Anyone with a better and reliable reproduction ?
You can try to add a list view with data template that display images. Open and close the page or switch to other pages. Do it for multiple times. That may reproduce the issue. Thanks
@hannahdo what device and api ? can you tell me also the Xamarin.Android version, are using VS or VS4Mac , stable channel updated?
Thanks
Catterpillar CAT S41 (Android V7.0)
I am using VS2017 with latest updates.
By the way you need to scroll the list view if you still cannot reproduce it. That may help. Thanks
It doesn't only appear on ListView btw.
I changed my UI for some other reason and the bug doesn't show anymore
we had this usually when we navigated from the first level of the app (the tab bars) one page down for example into the settings and then back. But it just did occur every 8 time or so. As far as we could find out, it happened when OnNotifyPropertyChanged was called.
In the end we moved away from ObservableCollections and implemented something more event based. Not quite elegant but it works so far.
I followed the steps, open master, go to list, scrolling the list down, click, go to details, click the MDP icon , go back to page 1, mdp icon go page with list and scroll , click and repeat .. like 20 times, and no crash. I dont have that device, i m using Pixel 2
This is fixed in the latest 3.1.0 stable. Please reopen if you still find this issue.
I am confirming that this does indeed appear to be fixed in 3.1.0.583944. All of my Android pre-launch automated tests are running to completion, whereas they were routinely crashing with this error in prior XF versions.
I'm on 3.1.0.583944 and it still throws ObjectDisposedException occasionally.
App Center shows me getting this same error 4 different times on 4 different devices with Xamarin Forms 3.1.0.583944:
Galaxy S9
LG G5
Stack
Galaxy S7
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)
ButtonRenderer.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.3aee9241-dd5c-464a-81b3-c638c559d638(intptr,intptr)
We were seeing a similar crash with a scrollview containing buttons, among other components. We narrowed down the issue to the buttons, and then discovered that the buttons were having the Disposed method called after Android had already Disposed of them, and so the exception was being thrown. We override the Dispose method in both the ScrollView and Button renderers to try to do the dispose, but catch the exception. We have some concern that this might introduce a leak, but it appears that Android has already freed the resources (and that a small memory leak is better than the app crashing at this point). We are using Xamarin.Forms 3.1.0.583944 and VS2017.
```
protected override void Dispose(bool disposing)
{
try
{
base.Dispose(disposing);
}
catch (Exception e)
{
Console.WriteLine("Exception handled.");
Console.WriteLine(e.Message);
}
}
@danger4386 ,I'm confused. Are you saying I would have to make custom button renderers?
@duzenko is it throwing with the same stacktrace as you initially opened this issue with ?
@BillyMartin1964 This issue manifests itself in a few different ways. Do you have a small repro by chance so we can see your use case?
@PureWeen , I'm afraid repro would be hard. According to App Center, it's only happened 1 time each with 4 different users out of hundreds. Still, I don't really want ANY crashes! LOL
@BillyMartin1964 How about a rough outline? Looking at your stack trace there are 3 or 4 different things that cause a FragmentContainer to dispose so I'm just curious what is going on with yours., Also are you using any custom renderers already? This can be a tricky one to debug because sometimes the issue comes from the user not properly disposing of resources in their own custom renderers.
@BillyMartin1964 Yes, we are using a custom button renderer for all the buttons in our application. We removed the custom renderer and were still seeing the crash with the ObjectDisposedException when navigating back from a page with a button. Here is the complete source for the CustomButtonRenderer. All it changes is to catch the ObjectDisposedException on the Dispose call. I'll note here that getting this exception is intermittent, sometimes it would crash the first time navigating back but most of the time it would take several transitions (sometimes more than 20 or 30 times navigating to the page with the button and back) to see the problem.
```
using System;
using Android.Content;
using NeedsGap.Droid.Renderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(Button), typeof(CustomButtonRenderer))]
namespace NeedsGap.Droid.Renderers
{
public class CustomButtonRenderer : ButtonRenderer
{
public CustomButtonRenderer(Context context) : base(context)
{
}
protected override void Dispose(bool disposing)
{
try
{
base.Dispose(disposing);
}
catch (ObjectDisposedException)
{
}
}
}
}
I can repeat this on a basic project without any custom renderer, etc.
disp2.zip
Click the auto test button and the app always crashes after a few navigation cycles.
What needs to be done here to reopen this bug?
@duzenko what device? API? are you testing on? I've ran your project on a few devices a few times and haven't received any crashes yet. It always gets to the "Test complete" dialog box for me
Samsung Tab S2, android 7.0.
Crashing every single time.
On Mon, Jul 16, 2018, 19:16 Shane Neuville notifications@github.com wrote:
@duzenko https://github.com/duzenko what device? API? are you testing
on? I've ran your project on a few devices a few times and haven't received
any crashes yet. It always gets to the "Test complete" dialog box for me—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/xamarin/Xamarin.Forms/issues/2004#issuecomment-405302207,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABacT-s4FrpxF2Jv_jTgYCBdCP979FeLks5uHLxlgaJpZM4SZ0sv
.
Created new android emulator based on Nexus 10.
Crashed on the first test run.
Again, what do I need to do to have this bug reopened?
It's as critical as it gets. The app crashes when users simply navigate pages, with no workaround available.
Btw it's leaking about 20KB on each page navigation on this simple page. In production I have pages with images and it's leaking 500KB per page.
I guess I'm abandoning Xamarin.Forms for good. Your bugs have wasted too much of my time and my coworkers'. It's been 4.5 months since the original bug report.
Here's the memory leak screenshot. Either GestureManager or ListViewRenderer is not unsubscribing itself from an event. BTW the current version of profiler is broken. Contact me via email if you're interested (I guess not).
@duzenko alright I dug out an old Android device and I'm able to recreate it on there consistently!!!
Pretty excited about that. This one has been a pain for some time so I really appreciate the repro and sticking with me on this one.
Hi,
Is the bug fixed or fix is in live?
Any news on this? It's a high impact bug which seem like it's always been there
@opcodewriter it's schedule for the current sprint so unless something unexpected happens it'll get fixed soon
@duzenko @Bhauraj001 @opcodewriter are you using fast renderers?
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/internals/fast-renderers
If not can you try and tell me if you still see the crash?
If you're using custom renderers those won't be using fast renderers (just an FYI) even if you enable them via the flags
@PureWeen I'm having the same issue.
Tried your suggestion to enable fast renderers, but it didn't solve the crash. Quite the opposite - an icon in my ListView's ViewCell went missing, but that's probably a story for another issue.
@PureWeen
I am using custom renderers in my production app so I am not going to even try fast renderers.
@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).
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!
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.
@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.)
I will test it when released publicly.
@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?
@PureWeen It does work now after I try your suggestion. Thank you. 👍
@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
https://github.com/xamarin/xamarin-android/issues/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!
Thank you for going forward with this issue
Adding [CachingStrategy="RecycleElement"] to your listview might help solve the issue.
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="fuchsia" >
and avoid setting your ItemSource to null just clear() it.
@cramirez070506 CachingStrategy="RecycleElement"
doesn't help preventing the issue
@PureWeen we had this issue despite having added the environment.txt as you described it. unless we did something wrong.
@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?
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.
@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
mh, I see. I'll let you know when I know more :)
@PureWeen
Preliminary tests of 3.2.0.729530-pre2 appear to have fixed this issue for my scenario!!! :smiley:
Many thanks and looking forward to GA. 👍
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)
@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.
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)
@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
Most helpful comment
@duzenko alright I dug out an old Android device and I'm able to recreate it on there consistently!!!
Pretty excited about that. This one has been a pain for some time so I really appreciate the repro and sticking with me on this one.