redth-org / BTProgressHUD

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

Crash on iOS 15 #84

Closed nicobarengo closed 3 years ago

nicobarengo commented 3 years ago

🐛 Bug Report

I have an app that im getting a lots of crash reports when the OS is updated to iOS 15.

System.NullReferenceException: Object reference not set to an instance of an object.

Stack trace

BigTed ProgressHUD.<DismissWorker>b__98_2 ()
Foundation NSActionDispatcher.Apply ()
(wrapper managed-to-native) ObjCRuntime.Messaging.objc_msgSend(intptr,intptr,intptr,intptr,bool)

Expected behavior

Not to crash

Reproduction steps

I believe that this is happening when the app is launched to do the background fetch and when its done the app crashes.

Configuration

Version: 1.3.3

Platform:

BramFP commented 3 years ago

Adding to this for additional information, we've also experienced some crashes on iOS 15 but haven't tracked down the root cause yet.

Ours originates from Acr.UserDialogs which incorporates BTProgressHUD and we've got a different stack trace though, but just dropping it in here in case it might help.

ProgressHUD.PositionHUD (Foundation.NSNotification notification)
ProgressHUD.ShowProgressWorker (System.Single progress, System.String status, BigTed.ProgressHUD+MaskType maskType, System.Boolean textOnly, BigTed.ProgressHUD+ToastPosition toastPosition, System.String cancelCaption, System.Action cancelCallback, System.Double timeoutMs, System.Boolean showContinuousProgress, UIKit.UIImage displayContinuousImage)
ProgressHUD+<>c__DisplayClass18_0.<Show>b__0 ()
NSActionDispatcher.Apply ()
(wrapper managed-to-native) ObjCRuntime.Messaging.objc_msgSend(intptr,intptr,intptr,intptr,bool)
NSObject.InvokeOnMainThread (System.Action action)
ProgressHUD.Show (System.String status, System.Single progress, BigTed.ProgressHUD+MaskType maskType, System.Double timeoutMs)
BTProgressHUD.Show (System.String status, System.Single progress, BigTed.ProgressHUD+MaskType maskType)
ProgressDialog+<>c__DisplayClass17_0.<Refresh>b__0 ()
NSActionDispatcher.Apply ()
(wrapper managed-to-native) ObjCRuntime.Messaging.objc_msgSend(intptr,intptr,intptr,intptr,bool)
NSObject.InvokeOnMainThread (System.Action action)
ProgressDialog.Refresh ()
ProgressDialog.Show ()
AbstractUserDialogs.Progress (Acr.UserDialogs.ProgressDialogConfig config)
AbstractUserDialogs.Loading (System.String title, System.Action onCancel, System.String cancelText, System.Boolean show, System.Nullable`1[T] maskType)
AbstractUserDialogs.ShowLoading (System.String title, System.Nullable`1[T] maskType)
mjo151 commented 3 years ago

I am also seeing a crash on iOS 15 when building against Xcode 13. I believe the problem is the use of UIApplication.SharedApplication.KeyWindow in the BTProgressHUB library. This property is deprecated and appears to be null in some cases, even after calling Window.MakeKeyAndVisible.

Cheesebaron commented 3 years ago

Hmm, interesting. I think we have to use UIApplication.SharedApplication.ConnectedScenes to get the foreground and active scene.

Cheesebaron commented 3 years ago

Can someone in this thread grab the artifact from this build and test my fix? https://github.com/redth-org/BTProgressHUD/pull/85/checks?check_run_id=3788006258

nicobarengo commented 3 years ago

Downloaded and installed... it's very unpredictable the crash, so I will get back with the results 🤞🏻

If someone need the NuGet for Acr.UserDialogs using the updated BTProgressHud (1.3.4) I made one for testing purposes Acr.UserDialogs NuGet

nicobarengo commented 3 years ago

@Cheesebaron I can confirm that the issue is resolved with the the latest build.

Cheesebaron commented 3 years ago

OK, that is cool. Thanks for testing.

Cheesebaron commented 3 years ago

1.3.4 has been released on NuGet

mjo151 commented 2 years ago

This doesn't appear to be completely resolved. Line 872 of ProgressHUD.cs is still accessing UIApplication.SharedApplication.KeyWindow. This resulted in an NRE when running my app.

Cheesebaron commented 2 years ago

@mjo151 can you please describe the scenario this happens in, so I can better test this?

mjo151 commented 2 years ago

We display a loading message at startup by calling BTProgressHUD.Show("Loading..."). The NRE occurs at that point and the stack trace indicates it is occurring on line 872 of ProgressHUD.cs. Looking at the code, I can see that UIApplication.SharedApplication.KeyWindow is still referenced.

Note that the problem doesn't happen every time the app is run, so it's not consistently reproducible.

mjo151 commented 2 years ago

@Cheesebaron please let me know if you need any additional information to track down this issue.

marcoburato commented 2 years ago

@Cheesebaron This is still not quite fixed, unfortunately. I've been adding some logging to my app to figure out why GetActiveWindow() would return null.

Here's the output from a crash report.

This is the normal condition immediately before calling BTProgressHUD.Show(), which works fine:

KeyWindow = <UIWindow: 0x10b510b10; frame = (0 0; 428 926); tintColor = UIExtendedSRGBColorSpace 0 0.588235 0.203922 1; gestureRecognizers = <NSArray: 0x283841380>; layer = <UIWindowLayer: 0x2838414d0>>
Windows =
  <UIWindow: 0x10b510b10; frame = (0 0; 428 926); tintColor = UIExtendedSRGBColorSpace 0 0.588235 0.203922 1; gestureRecognizers = <NSArray: 0x283841380>; layer = <UIWindowLayer: 0x2838414d0>>
    IsKeyWindow = True
    Hidden = False
    WindowLevel = 0
Scenes:
  <UIWindowScene: 0x104e12fb0; scene = <FBSScene: 0x281868600; identifier: sceneID:REDACTED>; persistentIdentifier = DEAEB509-D8BF-462C-9B07-15688ADF1DA8; activationState = UISceneActivationStateForegroundActive; settingsScene = <UIWindowScene: 0x104e12fb0>; windows = (
    "<UIWindow: 0x10b510b10; frame = (0 0; 428 926); tintColor = UIExtendedSRGBColorSpace 0 0.588235 0.203922 1; gestureRecognizers = <NSArray: 0x283841380>; layer = <UIWindowLayer: 0x2838414d0>>"
  )>
    Windows =
      <UIWindow: 0x10b510b10; frame = (0 0; 428 926); tintColor = UIExtendedSRGBColorSpace 0 0.588235 0.203922 1; gestureRecognizers = <NSArray: 0x283841380>; layer = <UIWindowLayer: 0x2838414d0>>
        IsKeyWindow = True
        Hidden = False
        WindowLevel = 0
ApplicationState = Active

This is the condition that causes the crash instead:

KeyWindow = 
Windows =
  <UIWindow: 0x10b510b10; frame = (0 0; 428 926); tintColor = UIExtendedSRGBColorSpace 0 0.588235 0.203922 1; gestureRecognizers = <NSArray: 0x283841380>; layer = <UIWindowLayer: 0x2838414d0>>
    IsKeyWindow = False
    Hidden = False
    WindowLevel = 0
Scenes:
  <UIWindowScene: 0x104d18db0; scene = <FBSScene: 0x281855380; identifier: sceneID:REDACTED>; persistentIdentifier = DEAEB509-D8BF-462C-9B07-15688ADF1DA8; activationState = UISceneActivationStateForegroundInactive; settingsScene = <UIWindowScene: 0x104d18db0>; windows = (
    "<UIWindow: 0x10b510b10; frame = (0 0; 428 926); tintColor = UIExtendedSRGBColorSpace 0 0.588235 0.203922 1; gestureRecognizers = <NSArray: 0x283841380>; layer = <UIWindowLayer: 0x2838414d0>>"
  )>
    Windows =
      <UIWindow: 0x10b510b10; frame = (0 0; 428 926); tintColor = UIExtendedSRGBColorSpace 0 0.588235 0.203922 1; gestureRecognizers = <NSArray: 0x283841380>; layer = <UIWindowLayer: 0x2838414d0>>
        IsKeyWindow = False
        Hidden = False
        WindowLevel = 0
ApplicationState = Inactive

Apparently, sometimes there is no KeyWindow and UIApplication.SharedApplication.ApplicationState == Inactive.

I'm not sure what the proper fix would be. My app, like most others, only uses a single window. So, it's easy to just pick the only existing one. In case of multiple windows, things are not so obvious. Perhaps in that use case it would make more sense to not use the convenience static methods and instead manually creating the ProgressHud with a new constructor that allows to specify the target window.

marcoburato commented 2 years ago

@Cheesebaron Can you reopen this issue based on my last comment? Or should I create a new one?

RobbiewOnline commented 2 years ago

Hi, I'm also experiencing this crash on iOS 15 intermittently. I'm using BTProgressHud 1.3.5 and the Xamarin crash is...

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 
brunck commented 2 years ago

@devology-rob you should open a new issue for this since this one is closed.

RobbiewOnline commented 2 years ago

@devology-rob you should open a new issue for this since this one is closed.

Thanks, I noticed afterwards and created #95 and it already looks like you may have fixed it 👏