-
Notifications
You must be signed in to change notification settings - Fork 423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix iPad tabs crash #2381
fix iPad tabs crash #2381
Conversation
let tab = tabManager.select(tabAt: index) | ||
select(tab: tab) | ||
} else { | ||
assertionFailure("Invalid index selected") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we could a debug pixel here to tell us how often this case is actually being triggered? (I'm not convinced that we do, but just asking anyway)
I was also wondering if we should default to selecting the last tab in the tab manager, in the case that the index somehow ends up being higher than the total count.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You got me thinking - I'm wondering if somehow the array is empty. It shouldn't be, but TabManager isn't really thread safe.
func clearAll() {
tabs.removeAll() // 1
tabs.append(Tab()) // 2
currentIndex = 0 // 3
}
1: at this point currentIndex will always be >= count and cause a problem if the array is accessed
2: if currentIndex >= 1 this could cause a problem
3: finally ok
Without adding a bunch of locking, could change it to this to tighten it up a bit:
func clearAll() {
currentIndex = 0
tabs = [Tab()]
}
Worth changing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a reasonable change. Tbh I would expect the tab manager to always be accessed from the main thread, but if that's not the case then yeah tidying this up sounds good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah that's a good point. I don't want to change too much so I'll leave it.
Am also going to not make the other changes you suggest:
- pixel: we'll see if this works as the crashes will go away, so doesn't seem useful (especially with triage overhead)
- set to last: if it is empty then that will likely cause some other problem. We can monitor feedback to see if folk complain about tab weirdness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing steps worked as expected 👍
Task/Issue URL: https://app.asana.com/0/414235014887631/1206390999092189/f
Tech Design URL:
CC:
Description:
Add some range guard for tab selection.
Steps to test this PR:
To force the issue update TabBarViewController.swift and change the following line:
to
Then long press the last tab - an assertion should occur.