HabitRPG / habitica-ios

Native iOS app for Habitica
GNU General Public License v3.0
712 stars 234 forks source link

Fix crash when opening a guild link #1271

Closed juanj closed 1 year ago

juanj commented 1 year ago

Closes #1267.

The app was crashing when opening a guild link because an IBOutlet on HabiticaSplitViewController.swift was accessed before it was loaded: Screenshot 2023-01-19 at 12 49 34

This sometimes happened because of a race condition. When handling a guild link, and instance of SplitSocialViewController is created, and the property groupID is set.

https://github.com/HabitRPG/habitica-ios/blob/a886a63330923d7f55f8493d920fd1c9615a0dfb/HabitRPG/Utilities/RouterHandler.swift#L70-L74

The property has a didSet property observer that dispatches a call to viewDidLayoutSubviews to the main thread. Most of the time, this call was executed before the view had a chance to be loaded and the IBOutles were connected. Thus crashing as soon as one of the outlet was accessed.

https://github.com/HabitRPG/habitica-ios/blob/a886a63330923d7f55f8493d920fd1c9615a0dfb/HabitRPG/UI/Social/SplitSocialViewController.swift#L24-L34

This PR fixes the crash by adding an extra check inside the viewDidLayoutSubviews method, to make sure IBOutles are not accessed before the view has been loaded.


Habitica User-ID: 2cedef5a-666a-484b-bd97-726209679923

saraolson commented 1 year ago

@juanj thanks so much for your contribution and patience! we've reviewed and tested this PR to be ready for release in the next version update. I've added record of this contribution to your Habitica account as well :)