redth-org / BTProgressHUD

Port to Xamarin.iOS of the SVProgressHUD
Other
118 stars 64 forks source link

iOS 15 still crashes intermittently #95

Closed RobbiewOnline closed 2 years ago

RobbiewOnline commented 2 years ago

πŸ› Bug Report

Attempting to display an iOS UIAlertView whilst a BTProgressHUD is still showing a spinner intermittently causes a crash.

❓ Expected behavior

Dialog to be displayed, with the ability to either dismiss the spinner before or after the UIAlertView is on screen.

πŸͺœ Reproduction steps

Display a progress spinner

BTProgressHUD.Show(message, -1, MaskType.Black);

Display a system dialog

UIAlertView avAlert = new UIAlertView(title, message, null, "OK", null);
avAlert.Show();

Try to dismiss the HUD after the Alert View is present

BTProgressHUD.Dismiss();

This often causes the crash.

πŸ›  Configuration

I would have said BTProgressHUD directly, however I discovered the 3rd party package ACR.UserDialogs in my installed NuGets, so I've removed that NuGet and it's still crashing.

πŸ“¦ Package Version: 1.3.5

πŸ“± iOS Version: iOS 15.5 Public Beta 3

πŸ’₯ Crash log:

MyProject 2022-05-04T22:10:59Z  UI  1 - IosPlatformDifferences - Display Message 'The pin does not match'

2022-05-04 23:11:06.324 MyProject.iOS[16396:1424514] [AppCenterCrashes] ERROR: +[MSACWrapperLogger MSACWrapperLog:tag:level:]/10 Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at BigTed.ProgressHUD.PositionHUD (Foundation.NSNotification notification) [0x000cf] in /_/BTProgressHUD/ProgressHUD.cs:872 
  at Foundation.InternalNSNotificationHandler.Post (Foundation.NSNotification s) [0x00000] in /Users/builder/azdo/_work/2/s/xamarin-macios/src/Foundation/NSNotificationCenter.cs:48 
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00013] in /Users/builder/azdo/_work/2/s/xamarin-macios/src/UIKit/UIApplication.cs:75 
  at MyProject.iOS.Application.Main (System.String[] args) [0x00001] in /Users/rob/GitHub/hillingar-MyProject-appv2/app/MyProject/MyProject.iOS/Main.cs:16 

2022-05-04 23:11:06.341 MyProject.iOS[16396:1424514] Unhandled managed exception: Object reference not set to an instance of an object (System.NullReferenceException)
  at BigTed.ProgressHUD.PositionHUD (Foundation.NSNotification notification) [0x000cf] in /_/BTProgressHUD/ProgressHUD.cs:872 
  at Foundation.InternalNSNotificationHandler.Post (Foundation.NSNotification s) [0x00000] in /Users/builder/azdo/_work/2/s/xamarin-macios/src/Foundation/NSNotificationCenter.cs:48 
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00013] in /Users/builder/azdo/_work/2/s/xamarin-macios/src/UIKit/UIApplication.cs:75 
  at MyProject.iOS.Application.Main (System.String[] args) [0x00001] in /Users/rob/GitHub/hillingar-MyProject-appv2/app/MyProject/MyProject.iOS/Main.cs:16 

πŸ€·πŸ»β€β™‚οΈ Workaround:

For some reason forcing a BTProgressHUD.Dismiss prior to display a system alert isn't enough on its own, however, delaying the alert by taking it off and back on the UI thread seems to do the trick πŸ€” However, usually I can display a popup whilst the spinner is still going.

        public override void DisplayMessage(string title, string message)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                Logger.Log(this, $"Display Message '{message}'");
                BTProgressHUD.Dismiss();
                Task.Delay(25).ContinueWith((t) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        UIAlertView avAlert = new UIAlertView(title, message, null, "OK", null);
                        avAlert.Show();
                    });
                });
            });
        }

Alternatively switching from UIAlertView to Xamarin Forms own DisplayAlert works without the hacky delays.

        public override void DisplayMessage(string title, string message)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                Logger.Log(this, $"Display Message '{message}'");
                PageManager.getMainPage().DisplayAlert(title, message, "OK");
            });
        }
brunck commented 2 years ago

I think #97 may be the one to fix this.

Cheesebaron commented 2 years ago

Can you check with the new 1.4.0 version?

RobbiewOnline commented 2 years ago

I can confirm that 1.4.0 does resolve the crashing issue

πŸ™ Thank you.

Sorry that it took a while to respond, I had to evert two different sections of code to re-create my original crash.