jml5qh
1
Here is the related code where I get the crash:
protocol MixedItemsPerRowFlowLayoutDelegate: NSObjectProtocol {
typealias TileType = SelfSizingCellProtocol & CellConfigurable
func tileAtIndexPath(_ indexPath: IndexPath) -> TileType?
func estimatedItemsPerRow() -> Int
}
class MixedItemsPerRowFlowLayout {
weak var flowLayoutDelegate: MixedItemsPerRowFlowLayoutDelegate?
func itemWidth(atIndexPath indexPath: IndexPath?) -> CGFloat {
if let delegate = self.flowLayoutDelegate, let indexPath = indexPath, let tile = delegate.tileAtIndexPath(indexPath) {
.....
}
}
}
This is a UICollectionViewLayout subclass. The MixedItemsPerRowFlowLayoutDelegate is a ViewController. The crash happens on the tileAtIndexPath call: protocol witness for MixedItemsPerRowFlowLayoutDelegate.tileAtIndexPath(_:). in conformance ViewController. Any ideas on what's going on? Unfortunately we're unable to reproduce, but see a bunch of instances in our crash logs.
Joe_Groff
(Joe Groff)
2
Is there any integer arithmetic in your implementation that might be overflowing?
jml5qh
3
This is the implementation:
func tileAtIndexPath(_ indexPath: IndexPath) -> MixedItemsPerRowFlowLayoutDelegate.TileType? {
return self.viewModel.tiles[indexPath.item]
}
Could it be that indexPath.item is out of bounds of the array?
Joe_Groff
(Joe Groff)
4
That seems like a likely cause of the trap, yeah.