0

Hi I tried to use compositional layout, while using stage manager rare the app getting crashed. Please refer below error message

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid absolute dimension: inf. The dimension must be a finite value.'

code

let itemSize = NSCollectionLayoutSize(widthDimension: .absolute(cellWidth),heightDimension: .absolute(cellHeight))
            let item = NSCollectionLayoutItem(layoutSize: itemSize)
            
            let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .absolute(cellHeight))
            let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
            group.interItemSpacing = NSCollectionLayoutSpacing.fixed(cellSpacing)
            
            let section = NSCollectionLayoutSection(group: group)
            section.contentInsets = NSDirectionalEdgeInsets(top: 10,leading: inset, bottom: 0,trailing:inset)
            section.interGroupSpacing = lineSpacing
iroh
  • 23
  • 5
  • On which line is your code crashing? What are the values of your variables (`cellWidth` ... `cellHeight` ... `cellSpacing` ...etc)? – DonMag Jul 05 '23 at 12:35
  • cell width and height are depends on container size( layoutEnvironment.container.contentSize) . The app crashes at the first line – iroh Jul 06 '23 at 04:54
  • I meant... when you debug this, what are the values you are getting for `cellWidth` and `cellHeight`? Are they what you *expect* to get? – DonMag Jul 06 '23 at 11:53

1 Answers1

-1
let itemSize = NSCollectionLayoutSize(widthDimension: .absolute(cellWidth),heightDimension: .absolute(cellHeight))

In case this line produces exception due to infinite parameter, that may happen due to division by zero when calculating cellWidth or cellHeight. I can assume you're diving total width of collection component by count of elements, or similar. Avoid division by zero issues by adding security checks for this edge case.