muak / AiForms.Effects

AiForms.Effects for Xamarin.Forms
MIT License
245 stars 27 forks source link

System.NullReferenceException on Android on page close #54

Closed alexpetin closed 4 years ago

alexpetin commented 4 years ago

Hi!

Page consist of CollectionView with ContentView Items with ef.AddCommand. On PopAsync (using FreshMvvm btw) app crashes. Android only, iOS - no problem.

Process: com.company.mobile, PID: 2026 android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object at AiForms.Effects.Droid.AiEffectBase+<>c__DisplayClass22_0.<BindingContextChanged>b__1 () [0x0000b] in <82332298958c45b498e83340cd785caa>:0 at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <e98afaf88af5496ea979d99b06e991b9>:0 at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <e98afaf88af5496ea979d99b06e991b9>:0 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.43(intptr,intptr)

alexpetin commented 4 years ago

Only Workaround is to set CollectionView ItemsSource to null at OnDisappearing... Probably the crash occurs when FreshMvvm set BindingContext to null before page close.

muak commented 4 years ago

@alexpetin Though I don't know FreshMvvm, It works fine using Prism.Forms or Navigation.PopAsync().

I think that it crashes at the following: https://github.com/muak/AiForms.Effects/blob/bd948f9e06e615909c692288a33955fde94f7274/AiForms.Effects.Droid/AiEffectBase.cs#L149-L165

If you know where the error occurs above, could you please tell me?

alexpetin commented 4 years ago

image

@muak Element is null here.

alexpetin commented 4 years ago

The problem disappears if I change that line to:

Not sure what would be more correct. Btw why BeginInvokeOnMainThread was used here?

muak commented 4 years ago

@alexpetin Thank you for the information.

I will fix with the above.

Without BeginInvokeOnMainThread, there was the pattern of occurring error. But I forgot what the pattern is.

Anyway, Thanks!