After updating Xcode to 8.3 and compiling for iOS 10.3 I now get a SIGABRT on release builds on an area of code that ran fine on the previous SDK.
malloc: * error for object 0x17415d0c0: Invalid pointer dequeued from free list * set a breakpoint in malloc_error_break to debug";
fileprivate var cache = [UICollectionViewLayoutAttributes]()
// ...
if cache.isEmpty {
let columnWidth = contentWidth / CGFloat(numberOfColumns())
var xOffset = [CGFloat]()
for column in 0 ..< numberOfColumns() {
xOffset.append(CGFloat(column) * columnWidth )
}
var column = 0
var yOffset = [CGFloat](repeating: 0, count: numberOfColumns())
for item in 0 ..< collectionView!.numberOfItems(inSection: 0) {
let indexPath = IndexPath(item: item, section: 0)
let width = columnWidth - cellPadding.x * 2
let cellHeight = delegate.collectionView(collectionView!, heightForCellAtIndexPath: indexPath,
withWidth:width)
let height = cellPadding.y + cellHeight + cellPadding.y
let frame = CGRect(x: xOffset[column], y: yOffset[column], width: columnWidth, height: height)
let insetFrame = frame.insetBy(dx: cellPadding.x, dy: cellPadding.y)
let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
attributes.frame = insetFrame
cache.append(attributes) // <------------ SIGABRT happens here
contentHeight = max(contentHeight, frame.maxY)
yOffset[column] = yOffset[column] + height
column = column >= (numberOfColumns() - 1) ? 0 : column + 1
}
}
I have no idea what is going on. I've tried reserving the capicity for the cache array, but the issue persists. It only happens on release builds, with whole module optimization (-Onone does not trigger this issue)