Closed arctouch-fabriciomiranda closed 5 years ago
hi @arctouch-fabriciomiranda !
Could you give me the exception stack for the Samsung Galaxy Prime J2 ?
Hello @roubachof. The same issue as @arctouch-fabriciomiranda append to me today with the following smarthone: Moto G4 Play.
My app is running Xamarin.Forms: 3.4.0.1029999 and Sharpnado: 0.9.9.
android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object at Sharpnado.Presentation.Forms.Droid.Renderers.HorizontalList.AndroidHorizontalListViewRenderer+RecycleViewAdapter.get_ItemCount () [0x00000] in
:0 at Android.Support.V7.Widget.RecyclerView+Adapter.n_GetItemCount (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in :0 at (wrapper dynamic-method) System.Object.84(intptr,intptr) --- End of stack trace from previous location where exception was thrown --- at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue args) [0x00089] in <6eb75ed2a7b64cccb6a2daf13f8f6b16>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue parameters) [0x0005d] in <6eb75ed2a7b64cccb6a2daf13f8f6b16>:0 at Android.Support.V7.Widget.RecyclerView.SetAdapter (Android.Support.V7.Widget.RecyclerView+Adapter adapter) [0x00031] in :0 at Sharpnado.Presentation.Forms.Droid.Renderers.HorizontalList.AndroidHorizontalListViewRenderer.UpdateItemsSource () [0x0002e] in :0 at Sharpnado.Presentation.Forms.Droid.Renderers.HorizontalList.AndroidHorizontalListViewRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00032] in :0 at (wrapper delegate-invoke) .invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs) at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00012] in <2ababf5361fa4e5a93abe01acecb2686>:0 at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in <2ababf5361fa4e5a93abe01acecb2686>: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) [0x0011b] in <2ababf5361fa4e5a93abe01acecb2686>: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 <2ababf5361fa4e5a93abe01acecb2686>:0 at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x00225] in <2ababf5361fa4e5a93abe01acecb2686>:0 at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in <2ababf5361fa4e5a93abe01acecb2686>:0 at Xamarin.Forms.BindingExpression+BindingExpressionPart. b49_0 () [0x00000] in <2ababf5361fa4e5a93abe01acecb2686>:0 at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <86a1acb1ff054c0caf25e14a33a83492>:0 at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr nativethis) [0x00009] in <86a1acb1ff054c0caf25e14a33a83492>:0 at (wrapper dynamic-method) System.Object.33(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:746) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5459) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
Great! Thank you both for the context. I think I have enough to work on this issue.
The issue remains in 0.9.11
Every time we call
Control.GetAdapter()?.Dispose();
inside an Android Custom renderer the app crashes
Great ! Now it seems you have a repro sample. Could you put it on a repo or just zip the source ?
Also now it's :
var oldAdapter = Control.GetAdapter();
var adapter = new RecycleViewAdapter(Element, Control, Context);
Control.SetAdapter(adapter);
oldAdapter?.Dispose();
@arctouch-fabriciomiranda @arctouch-joseclua
I will pushing a new version this week, so it would be amazing if you could send me a repro sample. It would be fixed by the end of the week then.
@FeynmanKenobi are you still encountering this issue with 0.9.11 ?
@roubachof thank you for response. I believe it would take quite some time to create a repro sample since it is not a simple project but I will check about that.
We would like to know if, by any chance, it would possible to enable SourceLink for source debugging?
I will have a look at SourceLink, but till then you can easily debug my code referencing the csprojs instead of using the nuget package (you just have to clone the repo)
@arctouch-fabriciomiranda @arctouch-joseclua @FeynmanKenobi I added some more checks in the last nuget version...
Is it still happening in 0.9.12 ?
Hi @roubachof thanks for that, however, the error still happens:
[Mono] DllImport searching in: 'libmono-btls-shared' ('./libmono-btls-shared.so').
[Mono] Searching for 'mono_btls_ssl_close'.
[Mono] Probing 'mono_btls_ssl_close'.
[Mono] Found as 'mono_btls_ssl_close'.
[Mono] DllImport searching in: 'libmono-btls-shared' ('./libmono-btls-shared.so').
[Mono] Searching for 'mono_btls_ssl_destroy'.
[Mono] Probing 'mono_btls_ssl_destroy'.
[Mono] Found as 'mono_btls_ssl_destroy'.
[MonoDroid] System.NullReferenceException: Object reference not set to an instance of an object.
[MonoDroid] at Sharpnado.Presentation.Forms.Droid.Renderers.HorizontalList.AndroidHorizontalListViewRenderer+RecycleViewAdapter.get_ItemCount () [0x00000] in D:\Dev\Sharpnado\src\Xamarin-Forms-Practices\Sharpnado.Presentation.Forms\Sharpnado.Presentation.Forms.Droid\Renderers\HorizontalList\AndroidHorizontalListViewRenderer.RecycleViewAdapter.cs:93
[MonoDroid] at Android.Support.V7.Widget.RecyclerView+Adapter.n_GetItemCount (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <7cd821e41c6245e986359cd08947256b>:0
[MonoDroid] at (wrapper dynamic-method) System.Object.88(intptr,intptr)
[Mono] DllImport searching in: 'libmono-btls-shared' ('./libmono-btls-shared.so').
[Mono] Searching for 'mono_btls_x509_store_free'.
[Mono] Probing 'mono_btls_x509_store_free'.
[Mono] Found as 'mono_btls_x509_store_free'.
[Mono] DllImport searching in: 'libmono-btls-shared' ('./libmono-btls-shared.so').
[Mono] Searching for 'mono_btls_ssl_ctx_free'.
[Mono] Probing 'mono_btls_ssl_ctx_free'.
[Mono] Found as 'mono_btls_ssl_ctx_free'.
[AppCenterCrashes] Unhandled Exception from source=AndroidEnvironment
[AppCenterCrashes] System.NullReferenceException: Object reference not set to an instance of an object.
[AppCenterCrashes] at Sharpnado.Presentation.Forms.Droid.Renderers.HorizontalList.AndroidHorizontalListViewRenderer+RecycleViewAdapter.get_ItemCount () [0x00000] in D:\Dev\Sharpnado\src\Xamarin-Forms-Practices\Sharpnado.Presentation.Forms\Sharpnado.Presentation.Forms.Droid\Renderers\HorizontalList\AndroidHorizontalListViewRenderer.RecycleViewAdapter.cs:93
[AppCenterCrashes] at Android.Support.V7.Widget.RecyclerView+Adapter.n_GetItemCount (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <7cd821e41c6245e986359cd08947256b>:0
[AppCenterCrashes] at (wrapper dynamic-method) System.Object.88(intptr,intptr)
...
[Mono] Assembly Ref addref Microsoft.AppCenter.Crashes[0xb82bcf70] -> System.Core[0xb83c26c0]: 19
...
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_new_byte_array'.
[Mono] Probing 'java_interop_jnienv_new_byte_array'.
[Mono] Found as 'java_interop_jnienv_new_byte_array'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_set_byte_array_region'.
[Mono] Probing 'java_interop_jnienv_set_byte_array_region'.
[Mono] Found as 'java_interop_jnienv_set_byte_array_region'.
[art] JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_throw'.
[Mono] Probing 'java_interop_jnienv_throw'.
[Mono] Found as 'java_interop_jnienv_throw'.
Thread finished: <Thread Pool> #24
Thread finished: <Thread Pool> #23
Thread finished: <Thread Pool> #25
Thread finished: <Thread Pool> #27
Thread finished: <Thread Pool> #29
Thread finished: <Thread Pool> #26
Thread finished: <Thread Pool> #28
...
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
Thread finished: <Thread Pool> #22
@roubachof, this is our custom renderer code, maybe it helps reproducing the error.
public class CustomHorizontalListViewRenderer : AndroidHorizontalListViewRenderer
{
private CustomHorizontalListView CustomElement => Element as CustomHorizontalListView;
public CustomHorizontalListViewRenderer(Context context)
: base(context)
{
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == CustomHorizontalListView.ItemsSourceProperty.PropertyName)
{
if(Element?.ItemsSource == null)
{
SafeAdapterDispose();
}
else
{
base.OnElementPropertyChanged(sender, e);
}
}
}
private void SafeAdapterDispose()
{
Control.GetAdapter()?.Dispose(); // <----------- ERROR HAPPENS HERE
}
}
@arctouch-joseclua if this is your FULL custom renderer I don't really understand what it's supposed to achieve. Also, by doing that, you're overriding the fix I did.
Just comment out the whole file and see if it still happens
@roubachof , this is not the full custom renderer code.
We also have a method for smoothing the scroll position.
...
if (e.PropertyName == CustomHorizontalListView.CenteredIndexProperty.PropertyName)
{
SmoothCenterIndex();
}
...
private void SmoothCenterIndex()
{
Control.PostDelayed(() =>
{
int centeredIndex = CustomElement?.CenteredIndex ?? -1;
if (centeredIndex != -1)
{
var viewHolder = Control.FindViewHolderForAdapterPosition(centeredIndex);
if (viewHolder != null)
{
var width = LinearLayoutManager.Width;
var offset = (width / 2) - (viewHolder.ItemView.Width / 2);
var newX = viewHolder.ItemView.Left - offset - Control.ScrollX;
// visible itens
Control.SmoothScrollBy(newX, 0);
}
else
{
// out of screen itens
Control.ScrollToPosition(centeredIndex);
Control.SmoothScrollToPosition(centeredIndex); // to force centralize
}
}
}, 50);
}
well, comment out you renderer and see if it still happens. If it's the code you added which creates the issue
We don't need to comment out the whole renderer to avoid the crash, commenting out just this line works:
Control.GetAdapter()?.Dispose();
Our concern is that we could be generating a memory leak if we take out that Dispose call, couldn't we?
I already dispose it in my renderer... You shoudn't have to mess with the adapter.
@arctouch-joseclua @arctouch-fabriciomiranda The case where ItemsSource
is null
is already taken care of here:
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(HorizontalListView.ItemsSource):
UpdateItemsSource();
break;
case nameof(HorizontalListView.CurrentIndex) when !_isCurrentIndexUpdateBackfire:
ScrollToCurrentItem();
break;
case nameof(HorizontalListView.DisableScroll):
ProcessDisableScroll();
break;
}
}
private void UpdateItemsSource()
{
InternalLogger.Info($"UpdateItemsSource()");
var oldAdapter = Control.GetAdapter();
var adapter = new RecycleViewAdapter(Element, Control, Context);
Control.SetAdapter(adapter);
oldAdapter?.Dispose();
if (Element.EnableDragAndDrop)
{
_dragHelper?.AttachToRecyclerView(null);
_dragHelper = new ItemTouchHelper(
new DragAnDropItemTouchHelperCallback(Element, adapter, Element.DragAndDropEndedCommand));
_dragHelper.AttachToRecyclerView(Control);
}
}
so @arctouch-joseclua did you try to remove the SafeAdapterDispose
method and see if the issue still happens ?
Hey @roubachof thanks for the support, we only had that line in the custom render until we were able to have a new release of the NuGet packet with this issue fixed, after removing our temporary fix it's now working with the latest release, thanks!
@arctouch-fabriciomiranda great news! I take all crash reports very seriously ;)
Platform (please complete the following information):
Describe the bug I could not reproduce the bug below, but it's happening in many users of our app, we have a dedicated QA team that also was unable to face current issue, but I would like to request at least a null checking in the give property that targets
_dataSource
that indeed might be null in some cases.Update: We have a device that it's happening consistently, which is a Samsung Galaxy Prime J2, after presenting the carousel if we leave the page to another section of the app we get the exception thrown in the
OnElementPropertyChanged
for theItemsSource
property.Exceptions (if applicable)