Rg.plugins.popup: Null reference exception while closing a popup

Created on 29 Jul 2018  路  9Comments  路  Source: rotorgames/Rg.Plugins.Popup

I'm seeing this with Xamarin.Forms version 3.1.0.637273.

System.NullReferenceException: Object reference not set to an instance of an object
at Rg.Plugins.Popup.IOS.Impl.PopupPlatformIos+d__10.MoveNext () [0x000f8] in :0

My source where the exception is occurring is:

await PopupNavigation.Instance.PopAsync(false);

Most helpful comment

you should check it before popping

 if (Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopupStack.Any())
                        {
                          await PopupNavigation.Instance.PopAsync();
                        }

if you look at the source code, it throws exception when there is no popup in the stack

  public Task PopAsync(bool animate = true)
        {
            animate = CanBeAnimated(animate);

            if (PopupStack.Count == 0)
                throw new IndexOutOfRangeException("There is not page in PopupStack");

            return RemovePageAsync(PopupStack.Last(), animate);
        }

All 9 comments

Another note: the popup is still visible after the exception occurs

Hi Have the same Issue, I got this message "there is not page in Popupstack" after
await PopupNavigation.Instance.PopAsync();

you should check it before popping

 if (Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopupStack.Any())
                        {
                          await PopupNavigation.Instance.PopAsync();
                        }

if you look at the source code, it throws exception when there is no popup in the stack

  public Task PopAsync(bool animate = true)
        {
            animate = CanBeAnimated(animate);

            if (PopupStack.Count == 0)
                throw new IndexOutOfRangeException("There is not page in PopupStack");

            return RemovePageAsync(PopupStack.Last(), animate);
        }

even though i am seeing this message for Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopAllAsync(); which is not supposed to throw it.
@rotorgames should we also check if any popup in the stack before using PopAllAsync? when I look at the source code PopAllAsync doesnt throw this exception it seems.

But why this error just happens in some devices, I only can reproduce this error in a Samsung Galaxy with Android 7.
But when it happens the Popup it's still visible, so the stack can not be empty.
So what's going on?

How do you reproduce it? Can you describe the steps and if possible give some code or repro project?

I need more information about this issue. If there are not any pages in PopupStack then all pages are removed. You need to check it before to use PopAsync.
P.S. Xamarin.Forms has similar behavior.

@EmilAlipiev I just have implemented throwing an exception if there are not any pages in PopupStack for PopAllAsync

I notice this is closed, but perhaps it shouldn't be. Just a 'me to' post on this. Works fine on Android, but ANY ATTEMPT to close the current popup on IOS via a button on the popup using either await PopupNavigation.Instance.PopAsync(); or await PopupNavigation.Instance.PopAllAsync();

Results in an exception:

System.IndexOutOfRangeException: There is not page in PopupStack

It matters not whether I check the stack before closing via 'if (PopupNavigation.Instance.PopupStack.Any())' it still crashes!!

Trying the operation on the MainThread also crashes in the same way:

Device.BeginInvokeOnMainThread(async () =>
{
if (PopupNavigation.Instance.PopupStack.Any())
await PopupNavigation.Instance.PopAllAsync();
});

Any route forward? Maybe I need to try a different version of the popup plugin or Xamarin.Forms. I am forced to use XF: 3.6.0.344457 as thus far all the 4.x releases feature a known bug that means that images don't load reliably in list controls on Android.

Using rg.Plugins.Popup V1.1.5.188

Nigel

@veletron2 Try to use the last version from Development NuGet: https://ci.appveyor.com/nuget/rg-plugins-popup-p6l5elugev99.

I fixed it many time ago but I still not publish a new version. I'm going to do it ASAP.

Was this page helpful?
0 / 5 - 0 ratings