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

fix iPad tabs crash #2381

merged 1 commit into from
Jan 25, 2024

Conversation

brindy
Copy link
Contributor

@brindy brindy commented Jan 24, 2024

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:

  1. Launch iPad
  2. Add a bunch of tabs
  3. Open + close, a few times
  4. Open enough to scroll
  5. Long press a tab - no crash should occur. If assertion occurs, capture the stack trace.

To force the issue update TabBarViewController.swift and change the following line:

delegate?.tabsBar(self, didSelectTabAtIndex: path.row + 1)

to

delegate?.tabsBar(self, didSelectTabAtIndex: path.row)

Then long press the last tab - an assertion should occur.

@brindy brindy requested review from a team and alessandroboron and removed request for a team January 24, 2024 22:05
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

Copy link
Contributor

@samsymons samsymons left a 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 👍

@brindy brindy merged commit 5cab245 into main Jan 25, 2024
12 checks passed
@brindy brindy deleted the brindy/fix-ipad-tabs-crash branch January 25, 2024 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants