-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Bug] iOS Shell PopAsync() causes null reference at RouteRequestBuilder #13947
Comments
Just discovered a workaround:
|
@paul-charlton can you attach a small reproduction of your issue please? I'll need a bit more information about your routes before I can debug this |
@holecekp Could you attach a sample where reproduce the issue? |
I have figured out when the crash happens. I have a button that opens a new page (await Shell.Current.Navigation.PushModalAsync(...)). The page however takes some time before it is rendered. Meanwhile, if the user manages to tap again on the button that calls PushModalAsync, the page opens all right, but the subsequent returning by PopAsync crashes the application. So the workaround is just to prevent multiple taps on the button: bool pageIsOpening = false;
private async void OpenPage(object sender, System.EventArgs e)
{
// Prevent clicking on the button multiple times as it crashes the app when the user returns back.
// https://github.com/xamarin/Xamarin.Forms/issues/13947
if (pageIsOpening)
return;
pageIsOpening = true;
var myPage = new MyPage();
await Shell.Current.Navigation.PushModalAsync(myPage);
pageIsOpening = false;
} I am not sure if this is a bug as calling PushModalAsync multiple times before the first call was handled is not very standard situation. @jsuarezruiz: Should I still create a repro project for this? Maybe, a more specific error message would be helpful in these cases instead of NRE on PopAsync. |
Apologies for the delay I've been trying to create a sample project without success. My issue is different to @holecekp in that this doesn't seem to be related to a long running rendering process, it's very much a push two additional pages then the pop fails. However, as mentioned I can't recreate in a sample project which means I'm more than likely doing something a bit odd somewhere. I'm using I'd be massively grateful if anyone has any suggestions as to where to look to resolve this!! |
This might fix your issue Instead of using and see if that fixes your exceptions? |
@PureWeen - gave that a try but it just doesn't do anything. No crashing though, but no navigation either. This works on the level lower where the error didn't occur. |
I've got a reproduction sample (https://github.com/paul-charlton/Bug_XamarinShellPopNavigation). To replicate - hit goto shell, then start, then push, push, push, pop. It seems to happen based on how the Shell.xaml has been laid out (the nested routes seem to be the issue). I've changed the startup project to this:
|
@paul-charlton I tested with the PR I linked to the issue here and it seems to fix your issue You can test the nuget here |
I have written in #13947 (comment) that the problem was solved in my case by preventing double tapping on a button that triggers the navigation. Now it seems that even though it helped a lot, this is not a perfect solution. I have received a report that my application still crashes occasionally on Android even after preventing double tapping. |
The issue is still there (XF 5.0 SR 5) but the type of exception changed. Instead of NRE, I am getting |
Description
On iOS (simulator and device) Using Shell I have navigated to 2 subsequent using GotoAsync(). If PopAsync() is then called a NullReferenceException is thrown (see below)
Steps to Reproduce
Expected Behavior
No Crash
Actual Behavior
Null Reference Exception:
System.NullReferenceException: Object reference not set to an instance of an object
at Xamarin.Forms.RouteRequestBuilder.g__AddNode|27_0 (Xamarin.Forms.BaseShellItem baseShellItem, System.String nextSegment) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Shell\RouteRequestBuilder.cs:77
at Xamarin.Forms.RouteRequestBuilder.AddMatch (Xamarin.Forms.ShellUriHandler+NodeLocation nodeLocation) [0x0003c] in D:\a\1\s\Xamarin.Forms.Core\Shell\RouteRequestBuilder.cs:70
at Xamarin.Forms.ShellUriHandler.SearchForGlobalRoutes (System.String[] segments, System.Uri startingFrom, Xamarin.Forms.ShellUriHandler+NodeLocation currentLocation, System.String[] routeKeys) [0x00042] in D:\a\1\s\Xamarin.Forms.Core\Shell\ShellUriHandler.cs:441
at Xamarin.Forms.ShellUriHandler.GenerateRoutePaths (Xamarin.Forms.Shell shell, System.Uri request, System.Uri originalRequest, System.Boolean enableRelativeShellRoutes) [0x00133] in D:\a\1\s\Xamarin.Forms.Core\Shell\ShellUriHandler.cs:288
at Xamarin.Forms.ShellUriHandler.GetNavigationRequest (Xamarin.Forms.Shell shell, System.Uri uri, System.Boolean enableRelativeShellRoutes, System.Boolean throwNavigationErrorAsException, Xamarin.Forms.ShellNavigationParameters shellNavigationParameters) [0x00018] in D:\a\1\s\Xamarin.Forms.Core\Shell\ShellUriHandler.cs:185
at Xamarin.Forms.ShellNavigationManager.GoToAsync (Xamarin.Forms.ShellNavigationParameters shellNavigationParameters) [0x000b8] in D:\a\1\s\Xamarin.Forms.Core\Shell\ShellNavigationManager.cs:44
at Xamarin.Forms.ShellSection+NavigationImpl.OnPopAsync (System.Boolean animated) [0x000e9] in D:\a\1\s\Xamarin.Forms.Core\Shell\ShellSection.cs:1070
Basic Information
Environment
Show/Hide Visual Studio info
The text was updated successfully, but these errors were encountered: