dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22k stars 1.72k forks source link

Java.Lang.NullPointerException at MauiAppCompatActivity.dispatchTouchEvent -crash #20698

Open Toomas75 opened 7 months ago

Toomas75 commented 7 months ago

Description

crc6488302ad6e9e4df1a.MauiAppCompatActivity.dispatchTouchEvent
MauiAppCompatActivity.java, line 57
Java.Lang.NullPointerException: Attempt to read from field 'int android.view.View.mPrivateFlags' on a null object reference

Crash log:
Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualBooleanMethod(JniObjectReference , JniObjectReference , JniMethodInfo , JniArgumentValue* )
Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualBooleanMethod(String , IJavaPeerable , JniArgumentValue* )
Android.App.Activity.DispatchTouchEvent(MotionEvent )
Microsoft.Maui.MauiAppCompatActivity.DispatchTouchEvent(MotionEvent )
Android.App.Activity.n_DispatchTouchEvent_Landroid_view_MotionEvent_(IntPtr jnienv, IntPtr native__this, IntPtr native_ev)
Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_Z(_JniMarshal_PPL_Z callback, IntPtr jnienv, IntPtr klazz, IntPtr p0)
java.lang.NullPointerException: Attempt to read from field 'int android.view.View.mPrivateFlags' on a null object reference
android.view.ViewGroup.resetCancelNextUpFlag ViewGroup.java:2750
android.view.ViewGroup.dispatchTouchEvent ViewGroup.java:2655
android.view.ViewGroup.dispatchTransformedTouchEvent ViewGroup.java:2968
android.view.ViewGroup.dispatchTouchEvent ViewGroup.java:2657
android.view.ViewGroup.dispatchTransformedTouchEvent ViewGroup.java:2968
android.view.ViewGroup.dispatchTouchEvent ViewGroup.java:2657
android.view.ViewGroup.dispatchTransformedTouchEvent ViewGroup.java:2968
android.view.ViewGroup.dispatchTouchEvent ViewGroup.java:2657
android.view.ViewGroup.dispatchTransformedTouchEvent ViewGroup.java:2968
android.view.ViewGroup.dispatchTouchEvent ViewGroup.java:2657
android.view.ViewGroup.dispatchTransformedTouchEvent ViewGroup.java:2968
android.view.ViewGroup.dispatchTouchEvent ViewGroup.java:2657
android.view.ViewGroup.dispatchTransformedTouchEvent ViewGroup.java:2968
android.view.ViewGroup.dispatchTouchEvent ViewGroup.java:2657
android.view.ViewGroup.dispatchTransformedTouchEvent ViewGroup.java:2968
android.view.ViewGroup.dispatchTouchEvent ViewGroup.java:2657
android.view.ViewGroup.dispatchTransformedTouchEvent ViewGroup.java:2968
android.view.ViewGroup.dispatchTouchEvent ViewGroup.java:2657
android.view.ViewGroup.dispatchTransformedTouchEvent ViewGroup.java:2968
android.view.ViewGroup.dispatchTouchEvent ViewGroup.java:2657
android.view.ViewGroup.dispatchTransformedTouchEvent ViewGroup.java:2968
android.view.ViewGroup.dispatchTouchEvent ViewGroup.java:2657
android.view.ViewGroup.dispatchTransformedTouchEvent ViewGroup.java:2968
android.view.ViewGroup.dispatchTouchEvent ViewGroup.java:2657
android.view.ViewGroup.dispatchTransformedTouchEvent ViewGroup.java:2968
android.view.ViewGroup.dispatchTouchEvent ViewGroup.java:2657
android.view.ViewGroup.dispatchTransformedTouchEvent ViewGroup.java:2968
android.view.ViewGroup.dispatchTouchEvent ViewGroup.java:2657
com.android.internal.policy.DecorView.superDispatchTouchEvent DecorView.java:448
com.android.internal.policy.PhoneWindow.superDispatchTouchEvent PhoneWindow.java:1829
android.app.Activity.dispatchTouchEvent Activity.java:3321
crc6488302ad6e9e4df1a.MauiAppCompatActivity.n_dispatchTouchEvent(Native Method)
crc6488302ad6e9e4df1a.MauiAppCompatActivity.dispatchTouchEvent MauiAppCompatActivity.java:57
androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent WindowCallbackWrapper.java:70
com.android.internal.policy.DecorView.dispatchTouchEvent DecorView.java:410
android.view.View.dispatchPointerEvent View.java:12016
android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent ViewRootImpl.java:4864
android.view.ViewRootImpl$ViewPostImeInputStage.onProcess ViewRootImpl.java:4678
android.view.ViewRootImpl$InputStage.deliver ViewRootImpl.java:4206
android.view.ViewRootImpl$InputStage.onDeliverToNext ViewRootImpl.java:4259
android.view.ViewRootImpl$InputStage.forward ViewRootImpl.java:4225
android.view.ViewRootImpl$AsyncInputStage.forward ViewRootImpl.java:4352
android.view.ViewRootImpl$InputStage.apply ViewRootImpl.java:4233
android.view.ViewRootImpl$AsyncInputStage.apply ViewRootImpl.java:4409
android.view.ViewRootImpl$InputStage.deliver ViewRootImpl.java:4206
android.view.ViewRootImpl$InputStage.onDeliverToNext ViewRootImpl.java:4259
android.view.ViewRootImpl$InputStage.forward ViewRootImpl.java:4225
android.view.ViewRootImpl$InputStage.apply ViewRootImpl.java:4233
android.view.ViewRootImpl$InputStage.deliver ViewRootImpl.java:4206
android.view.ViewRootImpl.deliverInputEvent ViewRootImpl.java:6749
android.view.ViewRootImpl.doProcessInputEvents ViewRootImpl.java:6723
android.view.ViewRootImpl.enqueueInputEvent ViewRootImpl.java:6684
android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent ViewRootImpl.java:6852
android.view.InputEventReceiver.dispatchInputEvent InputEventReceiver.java:187
android.os.MessageQueue.nativePollOnce(Native Method)
android.os.MessageQueue.next MessageQueue.java:325
android.os.Looper.loop Looper.java:142
android.app.ActivityThread.main ActivityThread.java:6518
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:438
com.android.internal.os.ZygoteInit.main ZygoteInit.java:807

Steps to Reproduce

8.0.10 nightly

Link to public reproduction project repository

No response

Version with bug

Nightly / CI build (Please specify exact version)

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

android 8.1

Did you find any workaround?

No response

Relevant log output

No response

ghost commented 7 months ago

Hi @Toomas75. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

jsuarezruiz commented 7 months ago

Do you a repro sample or maybe more logs or details?

Toomas75 commented 7 months ago

No repro. It's live app crashlog from appcenter. It happens occasionally. I see these after upgrade to .net 8.

mattleibow commented 7 months ago

This override was added in this PR: https://github.com/dotnet/maui/pull/16530

Not sure if this is related.

ghost commented 7 months ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

NatWobble commented 7 months ago

This override was added in this PR: #16530

Not sure if this is related.

I'm not using an Entry control or soft keyboard but I'm also seeing a few crash reports with similar stack traces from the last two published versions of my app using Maui 8.0.7 and 8.0.6. My app wasn't published with earlier versions. According to my Crashlytics logs, it looks like I'm on a screen using an SKGLTextureView but that's all know at this point.

Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'int android.view.View.mPrivateFlags' on a null object reference in method 'boolean android.view.ViewGroup.resetCancelNextUpFlag(android.view.View)' at android.view.ViewGroup.resetCancelNextUpFlag(ViewGroup.java:2895) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2800) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:500) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1912) at android.app.Activity.dispatchTouchEvent(Activity.java:4299) at crc6488302ad6e9e4df1a.MauiAppCompatActivity.n_dispatchTouchEvent(MauiAppCompatActivity.java) at crc6488302ad6e9e4df1a.MauiAppCompatActivity.dispatchTouchEvent(MauiAppCompatActivity.java:57) at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:70) at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:458) at android.view.View.dispatchPointerEvent(View.java:15309) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:6778) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:6578) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6034) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:6091) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:6057) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:6222) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:6065) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:6279) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6038) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:6091) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:6057) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:6065) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6038) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:9206) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:9157) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:9126) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:9329) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:267) at android.os.MessageQueue.nativePollOnce(MessageQueue.java) at android.os.MessageQueue.next(MessageQueue.java:335) at android.os.Looper.loopOnce(Looper.java:161) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7918) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

I've seen it on Android 11 and 13 devices and on Pixels, Vivos and Oppos so far.

NatWobble commented 6 months ago

@mattleibow Ignore my speculation regarding the SKGLTextureView. But I'm not using an Entry control or soft keyboard. If this is related to just touching the screen background or the root view (only guessing from the java stack trace), then the only place that I think this could be relevant in my app would be when tapping the background to close the fly out. I'm using a navigation page without shell.

NatWobble commented 6 months ago

@Toomas75

I was able to recreate the issue in my app. It is related to multi-touch where the second touch destroys the view or page etc.

It seems to be an Android issue, not a MAUI one.

This article on Medium explains what's going on very well.

I couldn't recreate the issue with 2 stock MAUI buttons. MAUI actually seems pretty robust there. I had some custom Android handlers that had their own touch listeners and those were causing the problem.

I attempted to fix the issue by setting android:splitMotionEvents to false, but that didn't work.

Since my controls didn't require multi-touch, I disabled it within my handlers:

if (e.Event.PointerCount > 0 && e.Event.GetPointerId(0) > 0 ) { e.Handled = true; return; };

Toomas75 commented 6 months ago

@NatWobble Thank you for the information! It's normal app behavior to close view on button click. App was developed in xamarin forms then upgraded to .net7 and now .net8. Prior .net8 this crash never happened. And stack shows: MauiAppCompatActivity.dispatchTouchEvent MauiAppCompatActivity.java, line 57 Haven't searched the maui code, but maybe it's possible to check if the view still exists before calling/dispatching touchEvent.

champcbg commented 6 months ago

@mattleibow Ignore my speculation regarding the SKGLTextureView. But I'm not using an Entry control or soft keyboard. If this is related to just touching the screen background or the root view (only guessing from the java stack trace), then the only place that I think this could be relevant in my app would be when tapping the background to close the fly out. I'm using a navigation page without shell.

@NatWobble your suggestion about the flyout helped me solve my issue.

I was having the same issue, I added popup before navigating to a new page. originally the popup close was after the navigation, that's when this error started. I moved the close of the popup to before the navigation to the new page and everything works as expected.

Toomas75 commented 3 weeks ago

Still an issue, but only on Android 8.1 devices. On android 10,12,13,14 does not happen