rhodgkins/RDHCollectionViewGridLayout

EXC_ARITHMETIC error

ppaulojr opened this issue · 6 comments

I'm getting an EXC_ARITHMETIC error (division by 0) when reloading a CollectionView using RDHCollectionViewGridLayout

Error Line:

frame = [self.firstLineFrames[indexPath.item % self.lineItemCount] CGRectValue];

Variables:

(lldb) po self
<RDHCollectionViewGridLayout: 0x7a74cbe0; scrollDirection = Vertical; lineDimension = (Size, 0.000); lineItemCount = 0; itemSpacing = 10.000; lineSpacing = 10.000; sectionsStartOnNewLine = YES>

(lldb) po indexPath
<NSIndexPath: 0x7a637a30> {length = 2, path = 0 - 0}

Stack:

* thread #1: tid = 0x538888, 0x00122388 imgur`-[RDHCollectionViewGridLayout calculateLayoutAttributesForItemAtIndexPath:](self=0x7a74cbe0, _cmd=0x001514a5, indexPath=0x7a637a30) + 312 at RDHCollectionViewGridLayout.m:341, queue = 'com.apple.main-thread', stop reason = EXC_ARITHMETIC (code=EXC_I386_DIV, subcode=0x0)
    frame #0: 0x00122388 imgur`-[RDHCollectionViewGridLayout calculateLayoutAttributesForItemAtIndexPath:](self=0x7a74cbe0, _cmd=0x001514a5, indexPath=0x7a637a30) + 312 at RDHCollectionViewGridLayout.m:341
  * frame #1: 0x001209a8 imgur`-[RDHCollectionViewGridLayout prepareLayout](self=0x7a74cbe0, _cmd=0x013ed93f) + 536 at RDHCollectionViewGridLayout.m:103
    frame #2: 0x011d70d2 UIKit`-[UICollectionViewData _prepareToLoadData] + 76
    frame #3: 0x011d78e0 UIKit`-[UICollectionViewData validateLayoutInRect:] + 68
    frame #4: 0x011973a3 UIKit`-[UICollectionView layoutSubviews] + 171
    frame #5: 0x00b007b1 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 608
    frame #6: 0x020c4771 libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70
    frame #7: 0x050b31cf QuartzCore`-[CALayer layoutSublayers] + 152
    frame #8: 0x050a7055 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 397
    frame #9: 0x050a6eb0 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 26
    frame #10: 0x050051b6 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 284
    frame #11: 0x0500658a QuartzCore`CA::Transaction::commit() + 392
    frame #12: 0x05006c56 QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92
    frame #13: 0x0234818e CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    frame #14: 0x023480d0 CoreFoundation`__CFRunLoopDoObservers + 400
    frame #15: 0x0233db0a CoreFoundation`__CFRunLoopRun + 1226
    frame #16: 0x0233d37b CoreFoundation`CFRunLoopRunSpecific + 443
    frame #17: 0x0233d1ab CoreFoundation`CFRunLoopRunInMode + 123
    frame #18: 0x04f6a2c1 GraphicsServices`GSEventRunModal + 192
    frame #19: 0x04f6a0fe GraphicsServices`GSEventRun + 104
    frame #20: 0x00a749b6 UIKit`UIApplicationMain + 1526
    frame #21: 0x000dc13d imgur`main(argc=1, argv=0xbff265d8) + 141 at main.m:14
    frame #22: 0x029fcac9 libdyld.dylib`start + 1

Hi @ppaulojr,

Thanks for the detailed error report 👍

Whats your data source details (number of sections, items in section this occurs in etc.) so I can reproduce, test and fix!

I'm a bit confused on how you managed to set a value of 0 for lineItemCount - this is whats causing it.

Cheers,

Rich

Oh actually, are you using this in a storyboard by any chance?

Yes. In a storyboard

For a temporary fix, set the Line Item Count property in the storyboard for the layout to your desired value.

I'll look into fixing this in the mean time! :)

Thanks!

Fixed and pushed to spec repo.

Thanks