Giphy / giphy-ios-sdk

Home of the GIPHY SDK iOS example app, along with iOS SDK documentation, issue tracking, & release notes.
https://developers.giphy.com/
Mozilla Public License 2.0
116 stars 52 forks source link

【Crash】Invalid batch updates detected #257

Closed FoneG closed 2 weeks ago

FoneG commented 1 month ago

🐛 Bug Report

I am reaching out to report a bug I've encountered after upgrading the Giphy SDK from version 2.1.22 to 2.2.9. This issue has been present since the initial integration, but after the recent upgrade, I’ve noticed a significant increase in its occurrence, particularly on iOS 17 and 18 devices.

Crash Details:

Fatal Exception: NSInternalInconsistencyException
Invalid batch updates detected: the number of sections and/or items returned by the data source before and after performing the batch updates are inconsistent with the updates. 
Data source before updates = { 1 section with item counts: [25] } 
Data source after updates = { 1 section with item counts: [25] } 
Updates = [ Insert item (0 - 0), Insert item (0 - 1), Insert item (0 - 2), ... , Insert item (0 - 24) ]
Collection view: <UICollectionView: 0x1088c1000; frame = (-196.5 -244.333; 393 488.667); ... ; layout: <GiphyUISDK.GPHWaterfallLayout: 0x14730c860>; dataSource: <GiphyUISDK.GiphyGridController: 0x108e1ca00>>

Additional Context: The SDK is integrated using Objective-C.

Although I do not explicitly call addChildViewController:, I persist the GiphyGridController objects via properties. I retain two instances of GiphyGridController due to the design of my app. I believe this should not affect how UICollectionView updates its data, but I wanted to provide this context for clarity.

Below is my initialization code for the GiphyGridController:


- (GiphyGridController *)tabGIFSearchVC
{
    if (_tabGIFSearchVC == nil) {
        _tabGIFSearchVC = [[GiphyGridController alloc] init];
        _tabGIFSearchVC.direction = UICollectionViewScrollDirectionVertical;

        GPHTheme *theme = [[GPHTheme alloc] init];
        theme.type = GPHThemeTypeDark;
        _tabGIFSearchVC.theme = theme;

        _tabGIFSearchVC.rating = GPHRatingTypeRatedG;
        _tabGIFSearchVC.cellPadding = 10.0;
        [_tabGIFSearchVC setNumberOfTracks:[self numberOfTracks]];
        _tabGIFSearchVC.renditionType = GPHRenditionTypeFixedHeightDownsampled;
        _tabGIFSearchVC.delegate = self;
        _tabGIFSearchVC.fixedSizeCells = YES;
        _tabGIFSearchVC.view.backgroundColor = UIColor.is_dark_mode_complexBackgroundColor1;
    }

    return _tabGIFSearchVC;
}

{
    self.tabGIFSearchVC.view.hidden = NO;
    if ([self.searchWord isNSStringAndNotEmpty]) {
        GPHMediaType mediaType = GPHMediaTypeSticker;
        if (_type == ISGIFSourceTypeGIF) {
            mediaType = GPHMediaTypeGif;
        }else if (_type == ISGIFSourceTypeText){
            mediaType = GPHMediaTypeText;
        }
        GPHContent *content = [GPHContent searchWithQuery:self.searchWord mediaType:mediaType language:GPHLanguageTypeEnglish includeDynamicResults:YES];
        self.tabGIFSearchVC.content = content;
    }else{
        if (self.type == GPHMediaTypeGif) {
            self.tabGIFSearchVC.content = [GPHContent trendingGifs];
        }else if (self.type == GPHMediaTypeSticker){
            self.tabGIFSearchVC.content = [GPHContent trendingStickers];
        }else{
            self.tabGIFSearchVC.content = [GPHContent trendingText];
        }
    }
    [self.tabGIFSearchVC update];
}

I would greatly appreciate any assistance or insights that could help resolve this issue, as it is currently affecting the stability of my application. Thank you in advance for your support, and I look forward to your response.

ALexanderLonsky commented 1 month ago

Hey @FoneG, Are you experiencing this issue in v2.2.11?

FoneG commented 1 month ago

Unfortunately, I was unable to reproduce this error in any version, so I'm not sure if it will be fixed after the upgrade. Can you check to see if you have already committed the code for this issue?

ALexanderLonsky commented 1 month ago

We were able to reproduce and fix this issue. However, using the latest version, I haven’t been able to reproduce the issue you're experiencing.

FoneG commented 1 month ago

I encountered this issue in version 2.2.9. Is it resolved in the version after that? Can I fix my problem by upgrading to v2.2.11?

FoneG commented 1 month ago

Hey @ALexanderLonsky, the crash issue is still persisting. Could you provide some more clarity or a definitive solution when possible? Appreciate your help!

I encountered this issue in version 2.2.9. Is it resolved in the version after that? Can I fix my problem by upgrading to v2.2.11?

ALexanderLonsky commented 1 month ago

It seems to be a different issue, and we haven’t been able to reproduce it yet. We’ll keep trying and work on resolving it. We’ll update you as we make progress.

ALexanderLonsky commented 1 month ago

Good news. We've successfully reproduced the crash, and the fix is on its way. It will be released later this week.

ALexanderLonsky commented 1 month ago

@FoneG A new version with the fix has been released: v2.2.13