apptekstudios / ASCollectionView

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

100% CPU and crash on animated change #149

Closed dmonagle closed 4 years ago

dmonagle commented 4 years ago

When a change with animation causes views to be added or removed from the collection in rapid succession, it causes a 100% CPU cycle and recursive attempts at a layout until the app crashes out of memory.

This only seems to happen if the next add/removal happens while the animation is still occurring.

To Reproduce

I've written a one page example app which causes this issue pretty easily.

https://github.com/dmonagle/TestASCollectionView

Note that the non animated controls can be used without a problem. The animated button can be used as long as you wait between button presses for the animation to finish. The use of the animated slider will freeze the app almost instantly.

Expected behaviour The cells should animate smoothly in and out no matter how fast the updates. This works fine a manually created CollectionView wrapped as a UIViewControllerRepresentable

Screenshots Instruments stack trace when issue occurs.

Screen Shot 2020-05-26 at 5 22 11 pm

Xcode Version: 11.5

Simulator, Device, Both? Simulators and Devices on iOS 13.5

apptekstudios commented 4 years ago

Thank you for the demo project David - I was easily able to reproduce the issue using it πŸŽ‰

This was due to certain situations resulting in an infinite cycle of calls to layoutSubviews. I have fixed the bug and will push a new version as soon as I have tested further πŸ‘

apptekstudios commented 4 years ago

The dev branch now contains this fix, you can point there for the time being πŸ˜ƒ

I've made quite a few changes so will test a little further before pushing the new version to master, however both the main demo app and your example app are functioning perfectly πŸ₯³

apptekstudios commented 4 years ago

Fixed in 1.7.0 πŸŽ‰