mokagio / UICollectionViewLeftAlignedLayout

A layout for UICollectionView that aligns the cells to the left.
MIT License
1.29k stars 178 forks source link

EXC_BAD_ACCESS #9

Open esetnik opened 8 years ago

esetnik commented 8 years ago

I am getting a crash when using UICollectionViewLeftAlignedLayout on line 47. This only occurs if I set estimatedItemSize to use dynamic sizing.

NSArray *originalAttributes = [super layoutAttributesForElementsInRect:rect];

mokagio commented 8 years ago

Hello @esetnik, thanks for the report. I shall look into it, but cannot guarantee it is going to be soon... If you find a solution please feel free to submit a PR

esetnik commented 8 years ago

I also filed a radar with Apple. I think this is an iOS bug because I get a similar crash when using the superclass flow layout. On Sun, Jan 3, 2016 at 2:53 AM Giovanni Lodi notifications@github.com wrote:

Hello @esetnik https://github.com/esetnik, thanks for the report. I shall look into it, but cannot guarantee it is going to be soon... If you find a solution please feel free to submit a PR

— Reply to this email directly or view it on GitHub https://github.com/mokagio/UICollectionViewLeftAlignedLayout/issues/9#issuecomment-168475731 .

Calvin-Huang commented 8 years ago

@esetnik Hello! Is any update for this circumstance? If I don't copy attribute, it would not cause EXC_BAD_ACCESS. But xcode will told me warning said "UICollectionViewFlowLayout has cached frame mismatch".

Thanks for your help!!

GMCoder commented 7 years ago

UICollectionViewLayoutAttributes* currentItemAttributes = [super layoutAttributesForItemAtIndexPath:indexPath]; delete copy fix this

kjartandoj-fette commented 7 years ago

I get the same "loop" that leads to the EXC_BAD_ACCESS bug on iOS 9.3 but not on iOS 10+

If I comment out this overwritten method in UICollectionViewLeftAlignedLayout.m then it works on iOS 9 (layout is left aligned) but the layout is not left aligned on iOS 10.

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    NSArray *originalAttributes = [super layoutAttributesForElementsInRect:rect];
    NSMutableArray *updatedAttributes = [NSMutableArray arrayWithArray:originalAttributes];
    for (UICollectionViewLayoutAttributes *attributes in originalAttributes)
    {
        if (!attributes.representedElementKind)
        {
            NSUInteger index = [updatedAttributes indexOfObject:attributes];
            updatedAttributes[index] = [self layoutAttributesForItemAtIndexPath:attributes.indexPath];
        }
    }

    return updatedAttributes;
}

Anyone found a way around this for iOS 9? Anyone knows how to at compile time exclude code based on iOS version?

screen shot 2017-01-03 at 10 07 00

dly553709938 commented 7 years ago

Thanks GMCoder.

Reproduce:

IOS 9, set estimatedItemSize property

michaelrevlis commented 5 years ago

iOS 9, According to this issue, it seems that an infinite loop occurs only when estimatedItemSize is larger than final itemSize. I set estimatedItemSize to CGSizeMake(1,1) to avoid crash. (Updated) Adding support for cell sizing is another solution