rotorgames / Rg.Plugins.Popup

Xamarin Forms popup plugin
MIT License
1.15k stars 336 forks source link

System.NullReferenceException When trying to pop a popup #704

Open NoamMani opened 2 years ago

NoamMani commented 2 years ago

Hi,

🐛 Bug Report

On iOS 15, sometimes we got this exception when we try to pop a specific popup:

`Exception: System.NullReferenceException: Object reference not set to an instance of an object. at Rg.Plugins.Popup.IOS.Impl.PopupPlatformIos.AddAsync (Rg.Plugins.Popup.Pages.PopupPage page) <0x105f87294 + 0x00460> in <c764561bc21b420689a747c209523bf2#9d0a4ec250688d50b764561a6d88ab00>:0 at Rg.Plugins.Popup.Services.PopupNavigationImpl.AddAsync (Rg.Plugins.Popup.Pages.PopupPage page) <0x105f897e8 + 0x0003f> in <c764561bc21b420689a747c209523bf2#9d0a4ec250688d50b764561a6d88ab00>:0 at Rg.Plugins.Popup.Services.PopupNavigationImpl+<>cDisplayClass20_0.b0 () <0x105f90804 + 0x0007b> in <c764561bc21b420689a747c209523bf2#9d0a4ec250688d50b764561a6d88ab00>:0 at Rg.Plugins.Popup.Services.PopupNavigationImpl+<>cDisplayClass28_0.b0 () <0x105f82440 + 0x0018b> in <c764561bc21b420689a747c209523bf2#9d0a4ec250688d50b764561a6d88ab00>:0 at Rg.Plugins.Popup.Services.PopupNavigationImpl+<>cDisplayClass23_0.b0 () <0x105f81c90 + 0x001e7> in <c764561bc21b420689a747c209523bf2#9d0a4ec250688d50b764561a6d88ab00>:0 at Rg.Plugins.Popup.Services.PopupNavigationImpl+<>cDisplayClass28_0.b0 () <0x105f82440 + 0x0018b> in <c764561bc21b420689a747c209523bf2#9d0a4ec250688d50b764561a6d88ab00>:0

Note we call "RemovePageAsync" and we got an exception from the "AddAsync" method.

Expected behavior

Pop the specific popup.

Configuration

Version: 2.0.0.13

Platform:

Thanks.

NoamMani commented 2 years ago

@dimonovdd public string PrintKeyWindow() { if (UIApplication.SharedApplication.KeyWindow == null) { return "Key Window in Null"; } var keyWindow = UIApplication.SharedApplication.KeyWindow.ToString(); return keyWindow; }

dimonovdd commented 2 years ago

Thnx, I think that I have idea

NoamMani commented 2 years ago

@dimonovdd Do you want to share with us? :)

dimonovdd commented 2 years ago

I'll try it tonight

dimonovdd commented 2 years ago

Sorry I've been very busy. I've checked few strange ways and I can't reproduce this error. But I think that PR #717 should solve it

AlonRom commented 2 years ago

@dimonovdd thanks, do you know if it will be integrated into the next Rg.Popup nuget version? we can test it on our side.

xleon commented 2 years ago

Having this issue on our production app on iOS devices 15+ massively. Turns out I have similar crashes in the code that references UIApplication.SharedApplication.KeyWindow

LuckyDucko commented 2 years ago

Its unusual how some production apps are having issues and some arent.

I haven't noticed any production issues on any of my iOS 15 devices, however lets hope this sorts out this slippery issue

xleon commented 2 years ago

yeah I'm not even able to reproduce it myself locally. Crazy stuff. But I will try it with some paths like opening the app from app links, background-foreground stuff, etc.

ramonB1996 commented 2 years ago

I have the same issue on my iOS 15+ device, but it is a race condition. If I click a button that will show a pop-up, right when the app started, then the KeyWindow is null and throws the exception. If I wait a few seconds longer, then it won't happen as the KeyWindow is known then.

xleon commented 2 years ago

Just here to say this bug is not reproducing any more with the latest version

AlonRom commented 2 years ago

@ramonB1996 is right, it's still happening but not always.