Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash with embedded CollectionView #699

Closed
shuhrat10 opened this issue Apr 25, 2017 · 11 comments
Closed

Crash with embedded CollectionView #699

shuhrat10 opened this issue Apr 25, 2017 · 11 comments
Labels
Milestone

Comments

@shuhrat10
Copy link

Hi,

I have CollectionView with embedded horizontal CollectionView. For example:

Category 1:
Items [Horizontal collectionView]
Category 2:
Items [Horizontal collectionView]
e.t.c.

When I start moving between sections and items my application crashed. It's not happening all the time. I'm not reloading any section, I think it's happening automatically when you move from top to the end. Any idea what can cause this issue? See attached screenshot for more details:

I'm using latest Xcode 8.3.2 and IGListKit from master branch. commit: ee4f3c9

Thank you.

iglistadapter_m

@shuhrat10 shuhrat10 changed the title Crash with embedded collectionView Crash with embedded CollectionView Apr 25, 2017
@rnystrom
Copy link
Contributor

@shuhrat10 do you have an example reproducing this issue? We had this happen internally this week and it ended up being implementation error.

When are you attaching the collection view to the adapter?

@shuhrat10
Copy link
Author

shuhrat10 commented Apr 25, 2017

Hi @rnystrom,

I don't have an example with this issue. It's happen in our new project today, and I wont be able to reproduce this crash. But I will keep testing to try reproduce this issue.

In viewDidLoad I set:

adapter.collectionView = collectionView
adapter.dataSource = self

and then

func objects(for listAdapter: IGListAdapter) -> [IGListDiffable] {
  return FeaturedLoader.shared.categories
}

I don't need to execute adapter.performUpdates(animated: true) because I all data ready for use before this controller will be initialized.

@rnystrom
Copy link
Contributor

@shuhrat10 where/how is the embedded adapter's collection view set?

@shuhrat10
Copy link
Author

shuhrat10 commented Apr 25, 2017

@rnystrom

In ViewController I have:

func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController {
    return CategorySectionController(height: 240)
  }
class CategorySectionController: IGListSectionController, IGListAdapterDataSource {


  // MARK: - Variables
  
  var model: Featured?
  var sectionHeight: CGFloat

  
  // MARK: - Lifecycle
  
  init(height: CGFloat, sectionInset: UIEdgeInsets? = nil) {
    sectionHeight = height
  }
  
  
  // MARK: - IGListAdapterDataSource

  lazy var adapter: IGListAdapter = {
    let adapter = IGListAdapter(updater: IGListAdapterUpdater(), viewController: self.viewController, workingRangeSize: 0)
    adapter.dataSource = self
    return adapter
  }()

  func objects(for listAdapter: IGListAdapter) -> [IGListDiffable] {
    guard let model = model else { return [] }
    return [model]
  }
  
  func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController {
    guard let object = object as? Featured, let type = object.type else { return PlaylistItemsController() }
    switch type {
    case .category:
      return CategoryItemsController()
    default:
      return PlaylistItemsController()
    }
  }
  
  func emptyView(for listAdapter: IGListAdapter) -> UIView? {
    return SpinnerView()
  }
  
  override func numberOfItems() -> Int {
    return 1
  }
  
  override func sizeForItem(at index: Int) -> CGSize {
    return CGSize(width: collectionContext!.containerSize.width, height: sectionHeight)
  }
  
  override func cellForItem(at index: Int) -> UICollectionViewCell {
    let cell = collectionContext?.dequeueReusableCellFromStoryboard(withIdentifier: String(describing: CategoryCell.self), for: self, at: index) as! CategoryCell
    guard let model = model else { return cell }
    cell.setupCell(item: model)
    adapter.collectionView = cell.collectionView
    return cell
  }
  
  override func didUpdate(to object: Any) {
    self.model = object as? Featured
  }
  
  override func didSelectItem(at index: Int) {
    
  }
  
}
class CategoryItemsController: IGListSectionController {
  
  
  // MARK: - Variables
  
  var model: Featured?
  
  
  // MARK: - Lifecycle
  
  override init() {
    super.init()
    inset = UIEdgeInsets(top: 0, left: 110, bottom: 0, right: 110)
    minimumLineSpacing = 46
  }
  
  override func numberOfItems() -> Int {
    guard let items = model?.items else { return 0 }
    return items.count
  }
  
  override func sizeForItem(at index: Int) -> CGSize {
    let height = collectionContext?.containerSize.height ?? 0
    return CGSize(width: 255, height: height)
  }
  
  override func cellForItem(at index: Int) -> UICollectionViewCell {
    let cell = collectionContext?.dequeueReusableCellFromStoryboard(withIdentifier: String(describing: CategoryItemCell.self), for: self, at: index) as! CategoryItemCell
    guard let item = model?.items?[index] else { return cell }
    cell.setup(item)
    return cell
  }
  
  override func didUpdate(to object: Any) {
    model = object as? Featured
  }
  
  override func didSelectItem(at index: Int) {

  }
  
}

PlaylistItemsController is not used at this time.

@shuhrat10
Copy link
Author

@rnystrom on tvOS you can super fast switch between sections and items with Siri Remote.

@shuhrat10
Copy link
Author

@rnystrom

(lldb) po self
IGListAdapter 0x17415d850:
  Updater type: IGListAdapterUpdater
  Data source: <App.CategorySectionController: 0x174321680>
  Collection view delegate: (null)
  Scroll view delegate: (null)
  Is in update block: No
  View controller: <App.GuideViewController: 0x1017f5e90>
  IGListAdapterUpdater instance 0x1742d26e0:
    Moves as deletes+inserts: No
    Allows background reloading: Yes
    Has queued reload data: No
    Queued update is animated: Yes
    State: Idle
  Section map details:
    Object and section controller at section: 0:
      SIVAPI.Featured
      <App.CategoryItemsController: 0x174301050>
  Collection view details:

(lldb) po self.collectionView
 nil
(lldb) 

@rnystrom
Copy link
Contributor

@shuhrat10 can you print the description of the embedded IGListAdapter?

You can also just (lldb) po [IGListDebugger dump] and put it in a gist. That will print all adapters in memory.

@shuhrat10
Copy link
Author

@rnystrom See bellow

(lldb) po [IGListDebugger dump]
IGListAdapter 0x170152e80:
  Updater type: IGListAdapterUpdater
  Data source: <App.CategorySectionController: 0x17412a5a0>
  Collection view delegate: (null)
  Scroll view delegate: (null)
  Is in update block: No
  View controller: <App.GuideViewController: 0x1017c4650>
  IGListAdapterUpdater instance 0x1702ddd50:
    Moves as deletes+inserts: No
    Allows background reloading: Yes
    Has queued reload data: No
    Queued update is animated: Yes
    State: Idle
  Section map details:
    Object and section controller at section: 0:
      SIVAPI.Featured
      <App.CategoryItemsController: 0x17011c7a0>
  Collection view details:
IGListAdapter 0x1701532a0:
  Updater type: IGListAdapterUpdater
  Data source: <App.CategorySectionController: 0x17412bd60>
  Collection view delegate: (null)
  Scroll view delegate: (null)
  Is in update block: No
  View controller: <App.GuideViewController: 0x1017c4650>
  IGListAdapterUpdater instance 0x1704c8b90:
    Moves as deletes+inserts: No
    Allows background reloading: Yes
    Has queued reload data: No
    Queued update is animated: Yes
    State: Idle
  Section map details:
    Object and section controller at section: 0:
      SIVAPI.Featured
      <App.CategoryItemsController: 0x17011b120>
  Collection view details:
IGListAdapter 0x174158520:
  Updater type: IGListAdapterUpdater
  Data source: <App.CategorySectionController: 0x17412e1a0>
  Collection view delegate: (null)
  Scroll view delegate: (null)
  Is in update block: No
  View controller: <App.GuideViewController: 0x1017c4650>
  IGListAdapterUpdater instance 0x1742de610:
    Moves as deletes+inserts: No
    Allows background reloading: Yes
    Has queued reload data: No
    Queued update is animated: Yes
    State: Idle
  Section map details:
    Object and section controller at section: 0:
      SIVAPI.Featured
      <App.CategoryItemsController: 0x174115f90>
  Collection view details:
IGListAdapter 0x170153090:
  Updater type: IGListAdapterUpdater
  Data source: <App.CategorySectionController: 0x17412e100>
  Collection view delegate: (null)
  Scroll view delegate: (null)
  Is in update block: No
  View controller: <App.GuideViewController: 0x1017c4650>
  IGListAdapterUpdater instance 0x1704c3c60:
    Moves as deletes+inserts: No
    Allows background reloading: Yes
    Has queued reload data: No
    Queued update is animated: Yes
    State: Idle
  Section map details:
    Object and section controller at section: 0:
      SIVAPI.Featured
      <App.CategoryItemsController: 0x174115a80>
  Collection view details:
IGListAdapter 0x170155450:
  Updater type: IGListAdapterUpdater
  Data source: <App.CategorySectionController: 0x17412e060>
  Collection view delegate: (null)
  Scroll view delegate: (null)
  Is in update block: No
  View controller: <App.GuideViewController: 0x1017c4650>
  IGListAdapterUpdater instance 0x1704c7930:
    Moves as deletes+inserts: No
    Allows background reloading: Yes
    Has queued reload data: No
    Queued update is animated: Yes
    State: Idle
  Section map details:
    Object and section controller at section: 0:
      SIVAPI.Featured
      <App.CategoryItemsController: 0x17011a5e0>
  Collection view details:
IGListAdapter 0x174157550:
  Updater type: IGListAdapterUpdater
  Data source: <App.GuideViewController: 0x1017c4650>
  Collection view delegate: (null)
  Scroll view delegate: (null)
  Is in update block: No
  View controller: <App.GuideViewController: 0x1017c4650>
  IGListAdapterUpdater instance 0x1742cc4e0:
    Moves as deletes+inserts: No
    Allows background reloading: Yes
    Has queued reload data: No
    Queued update is animated: Yes
    State: Idle
  Section map details:
    Object and section controller at section: 0:
      SIVAPI.Featured
      <App.CategorySectionController: 0x17412a5a0>
    Object and section controller at section: 1:
      SIVAPI.Featured
      <App.CategorySectionController: 0x17412cf80>
    Object and section controller at section: 2:
      SIVAPI.Featured
      <App.CategorySectionController: 0x17412de80>
    Object and section controller at section: 3:
      SIVAPI.Featured
      <App.CategorySectionController: 0x17412dfc0>
    Object and section controller at section: 4:
      SIVAPI.Featured
      <App.CategorySectionController: 0x17412e060>
    Object and section controller at section: 5:
      SIVAPI.Featured
      <App.CategorySectionController: 0x17412e100>
    Object and section controller at section: 6:
      SIVAPI.Featured
      <App.CategorySectionController: 0x17412bd60>
    Object and section controller at section: 7:
      SIVAPI.Featured
      <App.CategorySectionController: 0x17412e1a0>
  Collection view details:
IGListAdapter 0x17014f570:
  Updater type: IGListAdapterUpdater
  Data source: <App.CategorySectionController: 0x17412b220>
  Collection view delegate: (null)
  Scroll view delegate: (null)
  Is in update block: No
  View controller: <App.FeaturedMenuViewController: 0x10168d780>
  IGListAdapterUpdater instance 0x1702d6960:
    Moves as deletes+inserts: No
    Allows background reloading: Yes
    Has queued reload data: No
    Queued update is animated: Yes
    State: Idle
  Section map details:
    Object and section controller at section: 0:
      SIVAPI.Featured
      <App.PlaylistItemsController: 0x170118c00>
  Collection view details:
IGListAdapter 0x170152380:
  Updater type: IGListAdapterUpdater
  Data source: <App.CategorySectionController: 0x17412cf80>
  Collection view delegate: (null)
  Scroll view delegate: (null)
  Is in update block: No
  View controller: <App.GuideViewController: 0x1017c4650>
  IGListAdapterUpdater instance 0x1702ddf10:
    Moves as deletes+inserts: No
    Allows background reloading: Yes
    Has queued reload data: No
    Queued update is animated: Yes
    State: Idle
  Section map details:
    Object and section controller at section: 0:
      SIVAPI.Featured
      <App.CategoryItemsController: 0x1741145b0>
  Collection view details:
IGListAdapter 0x170153820:
  Updater type: IGListAdapterUpdater
  Data source: <App.CategorySectionController: 0x17412de80>
  Collection view delegate: (null)
  Scroll view delegate: (null)
  Is in update block: No
  View controller: <App.GuideViewController: 0x1017c4650>
  IGListAdapterUpdater instance 0x1704c40c0:
    Moves as deletes+inserts: No
    Allows background reloading: Yes
    Has queued reload data: No
    Queued update is animated: Yes
    State: Idle
  Section map details:
    Object and section controller at section: 0:
      SIVAPI.Featured
      <App.CategoryItemsController: 0x170119ce0>
  Collection view details:
IGListAdapter 0x174158f70:
  Updater type: IGListAdapterUpdater
  Data source: <App.CategorySectionController: 0x17412dfc0>
  Collection view delegate: (null)
  Scroll view delegate: (null)
  Is in update block: No
  View controller: <App.GuideViewController: 0x1017c4650>
  IGListAdapterUpdater instance 0x1742dc070:
    Moves as deletes+inserts: No
    Allows background reloading: Yes
    Has queued reload data: No
    Queued update is animated: Yes
    State: Idle
  Section map details:
    Object and section controller at section: 0:
      SIVAPI.Featured
      <App.CategoryItemsController: 0x170118780>
  Collection view details:
IGListAdapter 0x17014fdb0:
  Updater type: IGListAdapterUpdater
  Data source: <App.FeaturedMenuViewController: 0x10168d780>
  Collection view delegate: (null)
  Scroll view delegate: (null)
  Is in update block: No
  View controller: <App.FeaturedMenuViewController: 0x10168d780>
  IGListAdapterUpdater instance 0x1702ca9c0:
    Moves as deletes+inserts: No
    Allows background reloading: Yes
    Has queued reload data: No
    Queued update is animated: Yes
    State: Idle
  Section map details:
    Object and section controller at section: 0:
      SIVAPI.Featured
      <App.CategorySectionController: 0x17412b220>
  Collection view details:

(lldb) 

@shuhrat10
Copy link
Author

@rnystrom do you have any thoughts what is causing this crash?

@rnystrom
Copy link
Contributor

rnystrom commented May 8, 2017

@shuhrat10 ran into this internally as well, digging into this, sorry for the delay, something is out of whack 🤕

@rnystrom rnystrom added this to the 3.0.0 milestone May 8, 2017
@rnystrom rnystrom added bug and removed question labels May 8, 2017
@rnystrom
Copy link
Contributor

rnystrom commented May 8, 2017

@shuhrat10 I put together this example project trying to reproduce your conditions and can't get anything to crash on a real device or simulator. Could you take a look at this and let me know if there is something missing in the setup that could reproduce the crash? If you can get it to crash, mind re-uploading it?

IGLKPlayground.zip

edit: Aha! I got a sort-of repro. I don't know how to do it 100%, but I can eventually get it to crash. Diagnosing and fixing now.

edit2: Found the bug, PR incoming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants