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

Closing popup causes crash in IOS #25

Closed
Mous625 opened this issue Aug 29, 2022 · 11 comments
Closed

Closing popup causes crash in IOS #25

Mous625 opened this issue Aug 29, 2022 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@Mous625
Copy link

Mous625 commented Aug 29, 2022

Using the await MopupService.Instance.PopAsync() causes the app to crash specifically on IOS. On Android, all works well. You can see the error message and stack trace in the image attached.

301517862_606932141043297_6605776098673599441_n

If I wrap the await MopupService.Instance.PopAsync() in a try catch, the exception is swallowed however the app still crashes once the screen is touched. Error message and stack trace attached below:

301416691_491425982986049_6614557745973874674_n

Things to note:

The ConfigureMopups() line is added in MauiProgram.cs.
For navigation, I am using Shell.

Steps to reproduce (Screenshot 1):

  1. Open popup using await MopupService.Instance.PushAsync(<Popup>)
  2. Close popup using await MopupService.Instance.PopAsync()
  3. App crashes

Steps to reproduce with try-catch (screenshot 2):

  1. Open popup using await MopupService.Instance.PushAsync(<Popup>)
  2. Close popup using await MopupService.Instance.PopAsync() (exception doesn't cause crash)
  3. Tap on the app
  4. Exception is thrown in Program.cs
@Mous625
Copy link
Author

Mous625 commented Aug 29, 2022

@LuckyDucko tagging you here as I don't think I can assign you.

@LuckyDucko LuckyDucko self-assigned this Aug 29, 2022
@LuckyDucko
Copy link
Owner

@Mous625 all good, ill sort this one out asap, downgrading makes it work?

@Mous625
Copy link
Author

Mous625 commented Aug 29, 2022

@LuckyDucko Thank you for your prompt reply.

Just checked, and downgrading to 1.0.1 makes it work if closing the popup using MopupService manually. However, the error does occur if the user attempts to close the popup by swiping down on it.

P.S when I say manually I mean using the await MopupService.Instance.PopAsync() to a button event handler of my own making.

@LuckyDucko
Copy link
Owner

That makes sense, as its an issue with the HitTest function, ill let you know when its sorted 👍

@maxkoshevoi maxkoshevoi added the bug Something isn't working label Aug 29, 2022
@Mous625
Copy link
Author

Mous625 commented Aug 29, 2022

So curiosity got the better of me and I decided to have a look and added the Mopups project to my own. The error was happening when trying to cast a ViewCell to a VisualElement. I'm not an expert by any means, so I just added a try-catch to that section to ignore cast exceptions and it worked without issues. Please note I have no idea whether simply ignoring the ViewCell is the right approach but this may help speed up the process for you. Here is the code:

private static void DisposeModelAndChildrenHandlers(VisualElement view)
{
  foreach (VisualElement child in view.GetVisualTreeDescendants())
  {
    try //<-------- added by me
    {
        IViewHandler handler = child.Handler;
        child?.Handler?.DisconnectHandler();
        (handler?.PlatformView as UIView)?.RemoveFromSuperview();
        (handler?.PlatformView as UIView)?.Dispose();
    }
    catch(Exception){} //<-------- added by me
  }

  view?.Handler?.DisconnectHandler();
  (view?.Handler?.PlatformView as UIView)?.RemoveFromSuperview();
  (view?.Handler?.PlatformView as UIView)?.Dispose();
}

@LuckyDucko
Copy link
Owner

Still getting round to this, just been having issues with my Macbook, so i can't poke where the issues may be, sorry for the delay!

@LuckyDucko
Copy link
Owner

LuckyDucko commented Sep 7, 2022

@Mous625 could you provide a sample project for me to work off?

I just tested it then, and it seems to work quite fine on the default project. Perhaps its because you use shell?

Either way, I have a fix in mind, just wanting to get a test case running so I know

---EDIT----

Scratch that, I can probably just add any version of the "Cell" class in for testing

@LuckyDucko
Copy link
Owner

Screen Shot 2022-09-07 at 17 23 17

@Mous625 Does the following change fix the issue?

I dont understand why I settled on VisualElement, as this is much more robust if it works

@LuckyDucko
Copy link
Owner

This should be addressed by v 1.0.3

@Mous625
Copy link
Author

Mous625 commented Sep 18, 2022

My apologies I forgot to respond as I got bogged down by a new project. This fixes the issue. Thanks.

@Emtiaz-Tafsir
Copy link

Hello,
I just stumbled upon a rather unique encounter.
I am currently porting a Xamarin.Forms Application to MAUI. And I'm using Mopups as a replacement of RG.Popup. I'm still getting this error when trying to pop a page with ViewCells. I tried with both 1.1.1 and 1.2.0 nuget packages, but the problem persists.
Then I tried to debug with injecting the master code-base directly into my project and the problem went away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants