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

App not responding when open popup on Xamarin 5.0 above, issues happend only iOS version #664

Closed
nhuy-ecotech opened this issue Apr 9, 2021 · 15 comments
Labels

Comments

@nhuy-ecotech
Copy link

nhuy-ecotech commented Apr 9, 2021

🐛 Bug Report

App not responding when open popup on Xamarin Form 5.0 above, issues happend only iOS version. Please fix it.

Configuration

Xamarin Form version 5.0 above

Version: 1.x

Platform:

  • 📱 iOS
@cribia
Copy link

cribia commented Apr 9, 2021

I've got the same problem only App Forms Shell.
After updating Xamarin Forms the popup opens badly and when Close the last PopupPage int the PopupStack, the App crashing. Only iOS

@LuckyDucko
Copy link
Collaborator

@nhuy-ecotech have you tried updating to latest to fix the issue?

@cribia could you please provide a zipped project recreating the issue that I could troubleshoot the issue on? thank you

@cribia
Copy link

cribia commented Apr 13, 2021

AppPopupTestShell.zip
In the zipped project I sent, in ItemViewModel the pop up opens correctly (PushAsync) but in closing the pop up (PopAllAsync) crashing app.
the real project is much bigger so I have extrapolated the problem into a basic project.
The problem occurred after automatic update of xamarin.
Visual Studio for Mac 2019 version 8.9
Xamarin iOS version 14.14.2

@LuckyDucko
Copy link
Collaborator

hey @cribia while I could replicate your app crashing (froze for me), I updated the demo project for RG to test if it was latest xamarin fault, and it seemed to work fine.

When I traced it using your app,
first, I found an issue at awaiting a view controller being dismissed (something out of our control)
I switched this to what I assumed was the synchronous version and it passed that area, but still froze.

I think it may have something to do with how your popups are setup with ViewModels and whatnot.
If you want popups that return values asynchronously, may I shamelessly promote my nuget designed to help with that (open issues if something is broken, as I use this on my production app!)
Are you able to make an example of this crash using basic popups?

@ederjbezerra
Copy link

ederjbezerra commented Apr 27, 2021

Same issue here but not only iOS. Android also presents same problem.

@LuckyDucko
Copy link
Collaborator

@ederjbezerra could you provide an example project, or are you using @cribia's

@ederjbezerra
Copy link

ederjbezerra commented Apr 28, 2021

@ederjbezerra could you provide an example project, or are you using @cribia's

It's not cribia's project and it's a big project of one of my costumers, with almost 200mb, so it's complicated to share, I would have to take off a lot of code(I don't have much time nowadays). But here is what I'm using to reproduce the problem:

Android 11 physical device(galaxy S20+):

  • Xamarin.Forms 4.7.0.1080
  • Rg.Plugins.Popup 2.0.0.11

iOS 14.4.2 physical device:

  • Xamarin.Forms 5.0.0.2012
  • Rg.Plugins.Popup 2.0.0.11

If you push / pop some times repeatedly it freezes the application.

if (Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopupStack.Count > 0)
   await Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopAllAsync();

Removing these two lines above makes app freeze on iOs at first or second page push, but with these lines it works for 4/5 times before freeze app.

Then, after the if:

await Rg.Plugins.Popup.Services.PopupNavigation.Instance.PushAsync(new SharePage(UserID));

@LuckyDucko
Copy link
Collaborator

@ederjbezerra

Perhaps this is a threading issue, I could try and recreate this issue using the demo project, I just have some more questions

When you call the first snippet, is the assumption that you would have more than 1 page on the stack? or just 1 and greater?

Have you tried seeing if the crash happens if you remove the use of PopAllAsync, and instead go for something like a
foreach() which would just call await Instance.PopAsync?

Also, can you see if the crash happens when there is only 1 page on the popupstack?

I have some suspicions looking through the code of PopAllAsync and I'm wondering if deadlocks come forth because of the way it has been created.

@ederjbezerra
Copy link

@ederjbezerra

Perhaps this is a threading issue, I could try and recreate this issue using the demo project, I just have some more questions

When you call the first snippet, is the assumption that you would have more than 1 page on the stack? or just 1 and greater?

Have you tried seeing if the crash happens if you remove the use of PopAllAsync, and instead go for something like a
foreach() which would just call await Instance.PopAsync?

Also, can you see if the crash happens when there is only 1 page on the popupstack?

I have some suspicions looking through the code of PopAllAsync and I'm wondering if deadlocks come forth because of the way it has been created.

Bingo! Using foreach and popping each page solves the problem. And yes, having just one page also presents this issue.

@LuckyDucko
Copy link
Collaborator

Excellent, okay, so there is definitely something up with PopAllAsync. I'll look into it closer, glad i could help

@LuckyDucko LuckyDucko added the bug label May 23, 2021
@nchrisr
Copy link

nchrisr commented Jun 11, 2021

How were you able to work around this? I am currently having this issue, and I am thinking to downgrade my Xamarin.Forms version, is this what you did?

@LuckyDucko
Copy link
Collaborator

@Kikanye So, if you use PopAllAsync, instead see if you could use

            foreach (var popupPage in Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopupStack)
            {
                await Rg.Plugins.Popup.Services.PopupNavigation.Instance.RemovePageAsync(popupPage);
            }

OR you could use the following as well, I haven't tested it but its the same idea

            for (int stackCount = Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopupStack.Count; stackCount > 0; stackCount--)
            {
                await Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopAsync();
            }

@LuckyDucko LuckyDucko pinned this issue Jun 29, 2021
@darrabam
Copy link

darrabam commented Jul 3, 2021

@Kikanye So, if you use PopAllAsync, instead see if you could use

            foreach (var popupPage in Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopupStack)
            {
                await Rg.Plugins.Popup.Services.PopupNavigation.Instance.RemovePageAsync(popupPage);
            }

OR you could use the following as well, I haven't tested it but its the same idea

            for (int stackCount = Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopupStack.Count; stackCount > 0; stackCount--)
            {
                await Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopAsync();
            }

@LuckyDucko enumerating the stack with foreach and modifying its content will raise a System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.'

a simple workaround is to call ToList() which will copy the values to a separate list
foreach (var popupPage in Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopupStack.ToList()) { await Rg.Plugins.Popup.Services.PopupNavigation.Instance.RemovePageAsync(popupPage); }

@LuckyDucko
Copy link
Collaborator

LuckyDucko commented Jul 4, 2021

Ah, good point @darrabam, didn't give it too much thought as @ederjbezerra thought it fine, but I assume he tinkered it similar to what you had it.

I think I am going to change it to

while (PopupNavigation.Instance.PopupStack.Count > 0)
{
    await PopupNavigation.Instance.PopAsync(false);
}

As it seems the simplest way to go about it.

While the current way uses

var popupTasks = PopupStack.ToList().Select(page => RemovePageAsync(page, animate));
return Task.WhenAll(popupTasks);

It does seem to have an issue here or there.

@djhvscf
Copy link

djhvscf commented Jan 29, 2022

This is still not working for me. I had to downgrade to 2.0.0.7

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

No branches or pull requests

7 participants