{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/893","repository_url":"https://api.github.com/repos/facebook/AsyncDisplayKit","labels_url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/893/labels{/name}","comments_url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/893/comments","events_url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/893/events","html_url":"https://github.com/facebook/AsyncDisplayKit/issues/893","id":119328020,"number":893,"title":"[Supplementary Nodes] ASCollectionView crashed due to nil supplementary node?","user":{"login":"stowy","id":5924628,"avatar_url":"https://avatars.githubusercontent.com/u/5924628?v=3","gravatar_id":"","url":"https://api.github.com/users/stowy","html_url":"https://github.com/stowy","followers_url":"https://api.github.com/users/stowy/followers","following_url":"https://api.github.com/users/stowy/following{/other_user}","gists_url":"https://api.github.com/users/stowy/gists{/gist_id}","starred_url":"https://api.github.com/users/stowy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stowy/subscriptions","organizations_url":"https://api.github.com/users/stowy/orgs","repos_url":"https://api.github.com/users/stowy/repos","events_url":"https://api.github.com/users/stowy/events{/privacy}","received_events_url":"https://api.github.com/users/stowy/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/facebook/AsyncDisplayKit/labels/API%20improvement","name":"API improvement","color":"eb6420"},{"url":"https://api.github.com/repos/facebook/AsyncDisplayKit/labels/community%20debugging","name":"community debugging","color":"009b95"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/facebook/AsyncDisplayKit/milestones/11","html_url":"https://github.com/facebook/AsyncDisplayKit/milestones/1.9.3","labels_url":"https://api.github.com/repos/facebook/AsyncDisplayKit/milestones/11/labels","id":1443360,"number":11,"title":"1.9.3","description":null,"creator":{"login":"appleguy","id":565251,"avatar_url":"https://avatars.githubusercontent.com/u/565251?v=3","gravatar_id":"","url":"https://api.github.com/users/appleguy","html_url":"https://github.com/appleguy","followers_url":"https://api.github.com/users/appleguy/followers","following_url":"https://api.github.com/users/appleguy/following{/other_user}","gists_url":"https://api.github.com/users/appleguy/gists{/gist_id}","starred_url":"https://api.github.com/users/appleguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/appleguy/subscriptions","organizations_url":"https://api.github.com/users/appleguy/orgs","repos_url":"https://api.github.com/users/appleguy/repos","events_url":"https://api.github.com/users/appleguy/events{/privacy}","received_events_url":"https://api.github.com/users/appleguy/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":13,"state":"closed","created_at":"2015-12-04T03:24:51Z","updated_at":"2015-12-18T04:50:25Z","due_on":null,"closed_at":"2015-12-18T04:50:25Z"},"comments":16,"created_at":"2015-11-29T01:05:33Z","updated_at":"2016-10-11T14:36:07Z","closed_at":"2015-12-07T05:25:47Z","body":"I'm not sure why this is occurring, but when layoutSubviews is called on my ASCollectionViewController, it calls \r\n```objc \r\n- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath\r\n```\r\nand the node that is provided from \r\n```objc\r\nASCellNode *node = [_dataController supplementaryNodeOfKind:kind atIndexPath:indexPath];\r\n```\r\nis nil. Therefore it is not stored in `_completedNodes`.\r\n\r\nI've been scrutinizing this section of code in `ASCollectionDataController.mm`:\r\n\r\n```objc\r\n- (void)willInsertSections:(NSIndexSet *)sections\r\n{\r\n  [_pendingNodes enumerateKeysAndObjectsUsingBlock:^(NSString *kind, NSMutableArray *nodes, BOOL *stop) {\r\n    NSMutableArray *sectionArray = [NSMutableArray arrayWithCapacity:sections.count];\r\n    for (NSUInteger i = 0; i < sections.count; i++) {\r\n      [sectionArray addObject:[NSMutableArray array]];\r\n    }\r\n    \r\n    [self insertSections:sectionArray ofKind:kind atIndexSet:sections completion:nil];\r\n    [self batchLayoutNodes:nodes ofKind:kind atIndexPaths:_pendingIndexPaths[kind] completion:nil];\r\n    _pendingNodes[kind] = nil;\r\n    _pendingIndexPaths[kind] = nil;\r\n  }];\r\n}\r\n```\r\n\r\nThis is supposed to insert the pendingSections into the completed sections, however I may be missing something but the nodes never actually get added so I wonder if the completedNodes for the supplementary views ever get populated? It doesn't seem to be a problem with the rowNodes, only kind UICollectionElementKindSectionHeader at this point.\r\n\r\nIf this code works fine, then perhaps there is a race condition where layoutSubviews is being called when the completedNodes are being populated? This event seems to occur when I scroll to the bottom of my collection view, when the first UICollectionElementKindSectionHeader view is about to be displayed. It leads me to believe the supplementary view is not being correctly cached or I have a broken implementation. "},"comment":{"url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/comments/252935668","html_url":"https://github.com/facebook/AsyncDisplayKit/issues/893#issuecomment-252935668","issue_url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/893","id":252935668,"user":{"login":"benjaminhorner","id":3463436,"avatar_url":"https://avatars.githubusercontent.com/u/3463436?v=3","gravatar_id":"","url":"https://api.github.com/users/benjaminhorner","html_url":"https://github.com/benjaminhorner","followers_url":"https://api.github.com/users/benjaminhorner/followers","following_url":"https://api.github.com/users/benjaminhorner/following{/other_user}","gists_url":"https://api.github.com/users/benjaminhorner/gists{/gist_id}","starred_url":"https://api.github.com/users/benjaminhorner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjaminhorner/subscriptions","organizations_url":"https://api.github.com/users/benjaminhorner/orgs","repos_url":"https://api.github.com/users/benjaminhorner/repos","events_url":"https://api.github.com/users/benjaminhorner/events{/privacy}","received_events_url":"https://api.github.com/users/benjaminhorner/received_events","type":"User","site_admin":false},"created_at":"2016-10-11T14:36:06Z","updated_at":"2016-10-11T14:36:06Z","body":"Hi guys,\r\nSorry to cast bad news, but it seems the issue still lies here. I have a collectionViewNode with a supplementaryView.\r\n\r\nThe culprit is this line of code:\r\n```\r\nfunc collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {        \r\n        if collectionViewData.count > 0 {\r\n            return CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.width)\r\n        }\r\n        else {\r\n           return CGSize.zero\r\n        }\r\n}\r\n```\r\nThis works fine until I call **reloadData()** or **insertItemsAtIndexPaths**…\r\n\r\nIf I remove this, the error goes away… but so does my supplementaryView :("}}
{"actor":{"display_login":"benjaminhorner"}}