apptekstudios / ASCollectionView

A SwiftUI collection view with support for custom layouts, preloading, and more.
MIT License
1.35k stars 160 forks source link

Crash in prefetcher #194

Open paulfreeman opened 3 years ago

paulfreeman commented 3 years ago

Describe the bug When scrolling the PhotoView in the demo app the app crashed in the prefetcher call to the onCell prefetch method.

Crash occurred on onCellEvent?(.prefetchForData(data: dataToPrefetch)) in ASSectionDataSource

The call is on the background thread

    func prefetch(_ indexPaths: [IndexPath])
    {
        let dataToPrefetch: [Data] = indexPaths.compactMap
        {
            data[safe: $0.item]
        }
       onCellEvent?(.prefetchForData(data: dataToPrefetch)) 
    }

To Reproduce Run the demo app, rapidly scroll through photo content until the crash occurs. (I had been testing the memory by going in and out of the AppStore Layout view repeatedly prior to this).

ASCollectionView version Latest master (1.7)

Xcode Version: 12.1.1

Simulator, Device, Both? iPhone 12 pro Max, iOS 14.1