SIGABRT after updating to iOS 10.3/Xcode 8.3

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)

Did you test (with print), what attributes is ?


I found this which may provide some hints :


http : / / stackoverflow.com/questions/39414591/layoutattributesforelements-function-from-swift-2-gives-error-warning


I would also try to declare as :


var cache = [UICollectionViewLayoutAttributes] = [] // That should be equivalent, but may be there is some side effect ?

Attributes is as excpeted, a UICollectionViewLayoutAttributes. Not nill.


Changing how the array is initialized has no effect.

I've a similar problem with MapKit. Really interested by any advice...

I'm seeing the same thing with a proprietary (and heavily optimized) Objective-C module being used in a MacOS/Swift-3.1 application.


I can only reproduce the crash with with -O -whole-module-optimization turned on; it does not occur with -Onone or -O. There were no related crashes with older Xcode versions.

I'm seeing this problem on multiple areas of our codebase, we use whole module optimization. We are still trying to pin point the problem, I'll update this thread once we find more about it. Disabling Swift optimizations "fixes" the problems.


Update 1: Tried `-O` optimization level, it still crashes.

I'm seeing this problem on multiple areas of our codebase, we use whole module optimization.

Do we know if Xcode 8.3.1 fixes this?

Just upgraded to Xcode 8.3.1, and turning whole module optmiziation back on for our project did not fix it.

We're still seeing crashes in Xcode 8.3.1 with whole module optimization turned on.

Thanks for the info. Same with me. Still crashing with Xcode 8.3.1 whole module optimization turned on.

I am also experiencing this on our Swift 3 project in Xcode 8.3 if any kind of optimization is enabled. With optimization disabled the crashes are not happening.

The issue does not seem to be happening on Xcode 8.2.


Any help would be appreciated!

Updated to Xcode 8.3.2 and am still seeing my app crashing exclusively with whole module optimization turned on.

Accepted Answer

With Xcode 8.3.2 I no longer see the crash. If you are still experincing this crash you should open a new thread.

SIGABRT after updating to iOS 10.3/Xcode 8.3
 
 
Q