Open always19 opened 7 years ago
+1
+1
+1
I have the same problem, and my version (8.0.0) have the 7ff9ed7 changes :(
+1
+1
+1
The crash happens when the new viewControllers.count
is greater that the existing viewControllers.count
. The problem is that PagerTabStripViewController
which is the superclass of ButtonBarPagerTabStripViewController
, calls updateContent()
before the new cachedCellWidths
are calculated - the calculation is done in ButtonBarPagerTabStripViewController.reloadPagerTabStripView()
AFTER super.reloadPagerTabStripView()
is called
Here is a fix for the crash, which postpones the call to updateContent()
after everything is in place:
File: ButtonBarPagerTabStripViewController.swift
add a variable:
private var shouldUpdateContent = true
replace reloadPagerTabStripView() with:
open override func reloadPagerTabStripView() {
shouldUpdateContent = false
super.reloadPagerTabStripView()
shouldUpdateContent = true
guard isViewLoaded else { return }
buttonBarView.reloadData()
cachedCellWidths = calculateWidths()
updateContent()
buttonBarView.moveTo(index: currentIndex, animated: false, swipeDirection: .none, pagerScroll: .yes)
}
and add this function:
open override func updateContent() {
if shouldUpdateContent {
super.updateContent()
}
}
Thanks. @nickbit! This took many hours out of my day until I came upon this. Works great!
emm... when using @nickbit 's solution, i crashed in another place:
if !indexPathsToReload.isEmpty {
buttonBarView.reloadItems(at: indexPathsToReload)
}
with the log
Project(74688,0x700007fb1000) malloc: Heap corruption detected, free list is damaged at 0x600001f48000
*** Incorrect guard value: 105553124933760
Project(74688,0x10e4235c0) malloc: Heap corruption detected, free list is damaged at 0x600001f48020
*** Incorrect guard value: 5134468915308744792
Project(74688,0x700007fb1000) malloc: *** set a breakpoint in malloc_error_break to debug
Project(74688,0x10e4235c0) malloc: *** set a breakpoint in malloc_error_break to debug
@aalenliang I am also getting the same crash. Any update?
@dasSoumen
Have you tried call self.buttonBarView.layoutIfNeeded()
before self.reloadPagerTabStripView()
?
getting the same error Heap corruption detected, free list is damaged at reloadItems. if !indexPathsToReload.isEmpty { buttonBarView.reloadItems(at: indexPathsToReload) }
@aalenliang have u fixed it the issue heap corruption
@dasSoumen @ShoaibPathan Sorry for the late reply, i used george-lin/XLPagerTabStrip instead.
I'm still getting this error... I updated this library today with cocoa pods...any help?
Still getting this crash , Has somebody fixed this. Need help in this
For me, it wasn't crashing if I call reloadPagerTabStripView() from the switch of the same page in a different container. but if I call the same method just after page open then It was crashing. Here is the workaround I found to solve this issue temporary:: Just add the delay of 3 seconds.
extension DispatchQueue {
static func background(delay: Double = 0.0, background: (()->Void)? = nil, completion: (() -> Void)? = nil) {
DispatchQueue.global(qos: .background).async {
background?()
if let completion = completion {
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: {
completion()
})
}
}
}
}
USAGE---> SVProgressHUD.show() DispatchQueue.background(delay: 3.0, completion:{ // do something in main thread after 3 seconds reloadPagerTabStripView() SVProgressHUD.dismiss() })
this project needs to fork
updated on 24 Aug 2020 Still get error at : buttonBarView.reloadItems(at: indexPathsToReload)
any solution guys ?
Is there any solution for this? Will appreciate it
@nickbit I get 'cachedCellWidths' is inaccessible due to 'private' protection level
@minhmera try adding self.buttonBarView.layoutIfNeeded() before updateContent() with @nickbit answer. It seems to resolve the issue
Phenomenon
Crash by Index out of range because cachedCellWidths is not synched to viewControllers
Analysis
call stack
Environment