Skip to content
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

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,13 @@ class MainViewController: UIViewController {
func select(tabAt index: Int) {
viewCoordinator.navigationBarContainer.alpha = 1
allowContentUnderflow = false
let tab = tabManager.select(tabAt: index)
select(tab: tab)

if tabManager.model.tabs.indices.contains(index) {
let tab = tabManager.select(tabAt: index)
select(tab: tab)
} else {
assertionFailure("Invalid index selected")
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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

}
}

fileprivate func select(tab: TabViewController) {
Expand Down
Loading