Description
I'm seeing a few different exceptions all revolving around the DeviceDisplay.GetDefaultDisplay() method that causes a Xamarin Forms (Android) app to occasionally crash. Always has something to do with the orientation or orientation changing (although in the application/activity, orientation is fixed (ScreenOrientation = ScreenOrientation.Portrait)). We've recently locked rotation in the device and are waiting for results (a week or two to be safe).
This also seems to be heavily related to something XF.Material is doing, but I cannot see anything weird going on within that library that would cause issues (Simply calling the display orientation methods to determine the orientation for dialogs).
Could have something to do with the device? (We had some prior scanning crashes that was fixed in a system update), but I'm not sure...
Some of the logs:
Not sure what causes this
System.NotImplementedException: Do not know how to dispose: Invalid.
JniObjectReference.Dispose (Java.Interop.JniObjectReference& reference)
JniRuntime+JniValueManager.DisposePeer (Java.Interop.JniObjectReference h, Java.Interop.IJavaPeerable value)
JniRuntime+JniValueManager.DisposePeer (Java.Interop.IJavaPeerable value)
Object.Dispose ()
DeviceDisplay.GetDefaultDisplay ()
DeviceDisplay.GetMainDisplayInfo ()
DeviceDisplay.OnScreenMetricsChanged ()
Listener.OnOrientationChanged (System.Int32 orientation)
OrientationEventListener.n_OnOrientationChanged_I (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 orientation)
(wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.144(intptr,intptr,int)
Very similar to the above exception
System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Java.Lang.Object'.
JavaObjectExtensions._JavaCast[TResult] (Android.Runtime.IJavaObject instance)
JavaObjectExtensions.JavaCast[TResult] (Android.Runtime.IJavaObject instance)
Extensions.JavaCast[TResult] (Android.Runtime.IJavaObject instance)
DeviceDisplay.GetDefaultDisplay ()
DeviceDisplay.CalculateRotation ()
DeviceDisplay.GetMainDisplayInfo ()
DeviceDisplay.OnScreenMetricsChanged ()
Listener.OnOrientationChanged (System.Int32 orientation)
OrientationEventListener.n_OnOrientationChanged_I (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 orientation)
(wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.144(intptr,intptr,int)
Here XF.Material is simply calling DisplayOrientation = DeviceDisplay.MainDisplayInfo.Orientation; within the constructor.
System.ArgumentException: Handle must be valid. Parameter name: type
JniEnvironment+InstanceMethods.GetMethodID (Java.Interop.JniObjectReference type, System.String name, System.String signature)
JNIEnv.GetMethodID (System.IntPtr kls, System.String name, System.String signature)
IWindowManagerInvoker.get_DefaultDisplay ()
DeviceDisplay.GetDefaultDisplay ()
DeviceDisplay.CalculateRotation ()
DeviceDisplay.GetMainDisplayInfo ()
DeviceDisplay.get_MainDisplayInfo ()
XF.Material.Forms.UI.Dialogs.BaseMaterialModalPage..ctor () [0x0006d] in <fe8c4d3e01fc48d99ad74d87a7497997>:0
XF.Material.Forms.UI.Dialogs.MaterialLoadingDialog..ctor (System.String message, XF.Material.Forms.UI.Dialogs.Configurations.MaterialLoadingDialogConfiguration configuration) [0x00000] in <fe8c4d3e01fc48d99ad74d87a7497997>:0
MaterialLoadingDialog.Loading (System.String message, XF.Material.Forms.UI.Dialogs.Configurations.MaterialLoadingDialogConfiguration configuration)
Similar error to above, but another exception
System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Java.Lang.Object'.
JavaObjectExtensions._JavaCast[TResult] (Android.Runtime.IJavaObject instance)
JavaObjectExtensions.JavaCast[TResult] (Android.Runtime.IJavaObject instance)
Extensions.JavaCast[TResult] (Android.Runtime.IJavaObject instance)
DeviceDisplay.GetDefaultDisplay ()
DeviceDisplay.GetMainDisplayInfo ()
DeviceDisplay.get_MainDisplayInfo ()
XF.Material.Forms.UI.Dialogs.BaseMaterialModalPage..ctor () [0x0006d] in <fe8c4d3e01fc48d99ad74d87a7497997>:0
XF.Material.Forms.UI.Dialogs.MaterialLoadingDialog..ctor (System.String message, XF.Material.Forms.UI.Dialogs.Configurations.MaterialLoadingDialogConfiguration configuration) [0x00000] in <fe8c4d3e01fc48d99ad74d87a7497997>:0
MaterialLoadingDialog.Loading (System.String message, XF.Material.Forms.UI.Dialogs.Configurations.MaterialLoadingDialogConfiguration configuration)
From what I can tell, somethings unhappy with these lines of code. I'm honestly a bit stuck, the app works fine 99% of the time, then occasionally it will crash out with these errors. Not a super major issue (the users can just launch the app again and continue working as the state is stored in a remote database), just slightly annoying.
Further information that may help / might be indirectly causing these issues:
- The app is a simple scanning application, users scan barcodes, database calls are made, and the UI is updated.
- When the user scans something, the Panasonic ToughPad SDK (wrapped Java library) fires an event which I capture and then call an event handler
OnTextScanned.
- The Xamarin Forms app listens to this
OnTextScanned event and calls an async method (which does the processing) that shows a loading popup (the second set of exceptions), and an input dialog (the first set of exceptions).
- To avoid an
async void situtation, the async method is called as OnScanAsync(text).SafeFireAndForget() from this library
My alternate thoughts are that these crashes have something to do with the scan event handler and SafeFireAndForget() combined.
Steps to Reproduce
Unfortunately, unable to reproduce, have only heard about the issue and seen the crash logs.
Basic Information
- Version with issue: 1.6.1
- Last known good version: n/a
- IDE: n/a (Visual Studio 2019 16.9.2)
- Platform Target Frameworks:
- Android Support Library Version: n/a
- Nuget Packages:
- Affected Devices:
Panasonic FZ-N1
I'll try work on making a reproducible example, or writing up more information, but since these crashes are so intermittent, it may take a few weeks (so this issue is a low priority).
Description
I'm seeing a few different exceptions all revolving around the
DeviceDisplay.GetDefaultDisplay()method that causes a Xamarin Forms (Android) app to occasionally crash. Always has something to do with the orientation or orientation changing (although in the application/activity, orientation is fixed (ScreenOrientation = ScreenOrientation.Portrait)). We've recently locked rotation in the device and are waiting for results (a week or two to be safe).This also seems to be heavily related to something
XF.Materialis doing, but I cannot see anything weird going on within that library that would cause issues (Simply calling the display orientation methods to determine the orientation for dialogs).Could have something to do with the device? (We had some prior scanning crashes that was fixed in a system update), but I'm not sure...
Some of the logs:
Not sure what causes this
Very similar to the above exception
Here XF.Material is simply calling
DisplayOrientation = DeviceDisplay.MainDisplayInfo.Orientation;within the constructor.Similar error to above, but another exception
From what I can tell, somethings unhappy with these lines of code. I'm honestly a bit stuck, the app works fine 99% of the time, then occasionally it will crash out with these errors. Not a super major issue (the users can just launch the app again and continue working as the state is stored in a remote database), just slightly annoying.
Further information that may help / might be indirectly causing these issues:
OnTextScanned.OnTextScannedevent and calls an async method (which does the processing) that shows a loading popup (the second set of exceptions), and an input dialog (the first set of exceptions).async voidsitutation, the async method is called asOnScanAsync(text).SafeFireAndForget()from this libraryMy alternate thoughts are that these crashes have something to do with the scan event handler and
SafeFireAndForget()combined.Steps to Reproduce
Unfortunately, unable to reproduce, have only heard about the issue and seen the crash logs.
Basic Information
Panasonic FZ-N1
I'll try work on making a reproducible example, or writing up more information, but since these crashes are so intermittent, it may take a few weeks (so this issue is a low priority).