Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VirtualView cannot be null here #91

Open
azapatac opened this issue Oct 26, 2023 · 10 comments · Fixed by #100
Open

VirtualView cannot be null here #91

azapatac opened this issue Oct 26, 2023 · 10 comments · Fixed by #100

Comments

@azapatac
Copy link

azapatac commented Oct 26, 2023

Microsoft.Maui.Handlers.ViewHandler2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentViewGroup, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].get_VirtualView() Mopups.Platforms.Android.Renderers.PopupPageRenderer.OnLayout(Boolean changed, Int32 left, Int32 top, Int32 right, Int32 bottom) Android.Views.ViewGroup.n_OnLayout_ZIIII(IntPtr jnienv, IntPtr native__this, Boolean changed, Int32 l, Int32 t, Int32 r, Int32 b) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V(_JniMarshal_PPZIIII_V callback, IntPtr jnienv, IntPtr klazz, Boolean p0, Int32 p1, Int32 p2, Int32 p3, Int32 p4)

image
@prok155
Copy link
Contributor

prok155 commented Dec 19, 2023

I also saw the same crash in my google play console, but unfortunately can't reporduce that.

Fatal Exception: android.runtime.JavaProxyThrowable: System.InvalidOperationException: VirtualView cannot be null here
   at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentViewGroup, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].get_VirtualView()
   at Mopups.Platforms.Android.Renderers.PopupPageRenderer.OnLayout(Boolean changed, Int32 left, Int32 top, Int32 right, Int32 bottom)
   at Android.Views.ViewGroup.n_OnLayout_ZIIII(IntPtr jnienv, IntPtr native__this, Boolean changed, Int32 l, Int32 t, Int32 r, Int32 b)
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V(_JniMarshal_PPZIIII_V callback, IntPtr jnienv, IntPtr klazz, Boolean p0, Int32 p1, Int32 p2, Int32 p3, Int32 p4)
       at crc648efb837642500d81.PopupPageRenderer.n_onLayout(PopupPageRenderer.java)
       at crc648efb837642500d81.PopupPageRenderer.onLayout(PopupPageRenderer.java:62)
       at android.view.View.layout(View.java:16992)
       at android.view.ViewGroup.layout(ViewGroup.java:5409)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
       at android.view.View.layout(View.java:16992)
       at android.view.ViewGroup.layout(ViewGroup.java:5409)
       at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2483)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2185)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1314)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7057)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:829)
       at android.view.Choreographer.doCallbacks(Choreographer.java:606)
       at android.view.Choreographer.doFrame(Choreographer.java:576)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:815)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6939)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)```

@MarcosCostaDev
Copy link

MarcosCostaDev commented Jan 28, 2024

I just found the same issue on version 1.3.0 after the merge of #100

System.InvalidOperationException: 'VirtualView cannot be null here'

image

The scenario is when I try to close the popup via the service IPopupNavigation.PopAsync(); from a ViewModel which is the BindingContext of a ContentView, and I have two popups in the stack.

PublicKeyToken=null]].get_VirtualView () D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:42
Mopups.Platforms.Android.Renderers.PopupPageRenderer.OnLayout(Boolean changed, Int32 left, Int32 top, Int32 right, Int32 bottom)
ViewGroup.n_OnLayout_ZIIII (IntPtr jnienv, IntPtr native__this, Boolean changed, Int32 l, Int32 t, Int32 r, Int32 b) /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Views.ViewGroup.cs:3670
JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V (_JniMarshal_PPZIIII_V callback, IntPtr jnienv, IntPtr klazz, Boolean p0, Int32 p1, Int32 p2, Int32 p3, Int32 p4) /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:444

A workaround that I found is showing a alert before close the pop-up. In the situation that the bug happen, the pop-up is closed after a admob interstitial/reward ads is closed, then on the ads' close event happen, in this event, I close the pop-up. I change this behavior to show a alert before close the pop-up, this way the bug don't happen. My suspection is regarding the context of the application. Maybe I am trying to close the pop-up when its context is not in foreground. Showing a alert, it forces the user to back to the app context and then I am able to close the pop-up without any issue.

@romerotg
Copy link
Contributor

@LuckyDucko, I don't think this should be closed, as the issue is still occurring, as pointed out by @MarcosCostaDev.

@MarcosCostaDev, what do you mean by showing an alert before closing the popup? Can you share a code sample?

@MarcosCostaDev
Copy link

MarcosCostaDev commented Jan 31, 2024

@romerotg showing an alert means executing the alert function from the view model, like the code below.

Shell.Current.DisplayAlert("An alert Title", "An alert message", "close");

I execute the alert, then I close the popup via ViewModel using the function _popupNavigationService.PopAsync().

The error happens if I call _popupNavigationService.PopAsync() before calling the alert.

The scenario is specific. The event is triggered by the AdMob plugin when the ads close the interstitial ads and it will execute the _popupNavigationService.PopAsync(), then cause the problem.

@romerotg
Copy link
Contributor

romerotg commented Feb 2, 2024

@LuckyDucko

I created a PR to fix this issue #107 . Sometimes the OnLayout is called even after the page has been popped, and the handler disconnected. I made sure the reference to the handler is nulled out and the page renderer now checks that as well. The previous fix didn't work because the VirtualView property throws an exception ("VirtualView cannot be null here") when its inner field is null.

@tritter
Copy link

tritter commented Feb 7, 2024

@LuckyDucko +1 we also encountered this bug, fix looks to work would like to have a new package :)

@abdullahraiyyan
Copy link

I'm experiencing the same issue .is there any workaround?

@MarcosCostaDev
Copy link

@abdullahraiyyan try to call an alert before closing the popup, this works for me. However, there is a PR #107 with the bugfix

@mkazimoto
Copy link

mkazimoto commented Apr 5, 2024

I had this same error in CarouselView when calling the Clear() method:
ERRO

The error stopped happening when I avoided calling the Clear() method. Creating a temporary list and then assigning the entire list:
Correção erro

Performance is better because the request to update the visual controls is one time instead of multiple times.

@MarcosCostaDev
Copy link

@mkazimoto this looks like not be part of the Mopups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants