Crash: [NSCollectionViewData layoutAttributesForItemAtIndexPath]











up vote
5
down vote

favorite












Trying to understand this crash for days now.



For some users (Randomly, operation systems 10.14/10.14.1) app crashes on the first load.



Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000
-[NSCollectionViewData layoutAttributesForItemAtIndexPath:]

Crashed: com.apple.main-thread
0 UIFoundation 0x7fff7ac71c6a -[NSCollectionViewData layoutAttributesForItemAtIndexPath:] + 72
1 UIFoundation 0x7fff7ac3cb52 -[_NSCollectionViewCore _updateVisibleCellsNow:] + 7748
2 UIFoundation 0x7fff7ac358a9 -[_NSCollectionViewCore _layoutItems] + 298
3 AppKit 0x7fff5019dbc2 -[NSCollectionView layout] + 360
4 AppKit 0x7fff5002e755 _NSViewLayout + 587
5 AppKit 0x7fff5002e0fc -[NSView _layoutSubtreeWithOldSize:] + 446
6 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
7 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
8 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
9 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
10 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
11 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
12 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
13 AppKit 0x7fff5002bb96 -[NSView _layoutSubtreeIfNeededAndAllowTemporaryEngine:] + 1358
14 AppKit 0x7fff5002b332 -[NSWindow(NSConstraintBasedLayout) _layoutViewTree] + 148
15 AppKit 0x7fff5003cfee -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 263
16 AppKit 0x7fff50041469 -[NSWindow displayIfNeeded] + 180
17 AppKit 0x7fff5004130f __NSWindowGetDisplayCycleObserverForDisplay_block_invoke + 722
18 AppKit 0x7fff5003c41a NSDisplayCycleObserverInvoke + 170
19 AppKit 0x7fff5003bf8f NSDisplayCycleFlush + 1073
20 QuartzCore 0x7fff5d9621d3 CA::Transaction::run_commit_handlers(CATransactionPhase) + 49
21 QuartzCore 0x7fff5d961b9a CA::Transaction::commit() + 186
22 AppKit 0x7fff5003b8f5 __65+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayRefresh]_block_invoke + 274
23 CoreFoundation 0x7fff52a3f95d __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
24 CoreFoundation 0x7fff52a3f892 __CFRunLoopDoObservers + 452
25 CoreFoundation 0x7fff529e13c5 __CFRunLoopRun + 1166
26 CoreFoundation 0x7fff529e0ce4 CFRunLoopRunSpecific + 463
27 HIToolbox 0x7fff51c7a895 RunCurrentEventLoopInMode + 293
28 HIToolbox 0x7fff51c7a5cb ReceiveNextEventCommon + 618
29 HIToolbox 0x7fff51c7a348 _BlockUntilNextEventMatchingListInModeWithFilter + 64
30 AppKit 0x7fff4ff3795b _DPSNextEvent + 997
31 AppKit 0x7fff4ff366fa -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1362
32 AppKit 0x7fff4ff3075d -[NSApplication run] + 699
33 AppKit 0x7fff4ff1fe97 NSApplicationMain + 780
34 TodoDock 0x105173a99 main (AppDelegate.swift:18)
35 libdyld.dylib 0x7fff7fa7a085 start + 1


By the looks of it, it seems the app didn't event load yet.



I even managed to get to a guy that had the same issue, installed Xcode on his machine and run the same version locally, and everything worked!
Not only that but after I did, the downloaded app worked too! This is so strange, I really do not have a clue what is going on.
And more users are expirancing this, but not all of them.










share|improve this question
























  • Maybe a dangling pointer. Have you checked this thread ?
    – gulyashki
    Nov 24 at 16:09












  • @gulyashki yes I did. I want over all places that used blocks or delegates to check for memory leaks, and profiled for leaks, with none found. I do not really think this is the issue since it happens on load before the app is even shown.
    – MCMatan
    Nov 24 at 16:41















up vote
5
down vote

favorite












Trying to understand this crash for days now.



For some users (Randomly, operation systems 10.14/10.14.1) app crashes on the first load.



Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000
-[NSCollectionViewData layoutAttributesForItemAtIndexPath:]

Crashed: com.apple.main-thread
0 UIFoundation 0x7fff7ac71c6a -[NSCollectionViewData layoutAttributesForItemAtIndexPath:] + 72
1 UIFoundation 0x7fff7ac3cb52 -[_NSCollectionViewCore _updateVisibleCellsNow:] + 7748
2 UIFoundation 0x7fff7ac358a9 -[_NSCollectionViewCore _layoutItems] + 298
3 AppKit 0x7fff5019dbc2 -[NSCollectionView layout] + 360
4 AppKit 0x7fff5002e755 _NSViewLayout + 587
5 AppKit 0x7fff5002e0fc -[NSView _layoutSubtreeWithOldSize:] + 446
6 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
7 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
8 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
9 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
10 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
11 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
12 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
13 AppKit 0x7fff5002bb96 -[NSView _layoutSubtreeIfNeededAndAllowTemporaryEngine:] + 1358
14 AppKit 0x7fff5002b332 -[NSWindow(NSConstraintBasedLayout) _layoutViewTree] + 148
15 AppKit 0x7fff5003cfee -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 263
16 AppKit 0x7fff50041469 -[NSWindow displayIfNeeded] + 180
17 AppKit 0x7fff5004130f __NSWindowGetDisplayCycleObserverForDisplay_block_invoke + 722
18 AppKit 0x7fff5003c41a NSDisplayCycleObserverInvoke + 170
19 AppKit 0x7fff5003bf8f NSDisplayCycleFlush + 1073
20 QuartzCore 0x7fff5d9621d3 CA::Transaction::run_commit_handlers(CATransactionPhase) + 49
21 QuartzCore 0x7fff5d961b9a CA::Transaction::commit() + 186
22 AppKit 0x7fff5003b8f5 __65+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayRefresh]_block_invoke + 274
23 CoreFoundation 0x7fff52a3f95d __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
24 CoreFoundation 0x7fff52a3f892 __CFRunLoopDoObservers + 452
25 CoreFoundation 0x7fff529e13c5 __CFRunLoopRun + 1166
26 CoreFoundation 0x7fff529e0ce4 CFRunLoopRunSpecific + 463
27 HIToolbox 0x7fff51c7a895 RunCurrentEventLoopInMode + 293
28 HIToolbox 0x7fff51c7a5cb ReceiveNextEventCommon + 618
29 HIToolbox 0x7fff51c7a348 _BlockUntilNextEventMatchingListInModeWithFilter + 64
30 AppKit 0x7fff4ff3795b _DPSNextEvent + 997
31 AppKit 0x7fff4ff366fa -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1362
32 AppKit 0x7fff4ff3075d -[NSApplication run] + 699
33 AppKit 0x7fff4ff1fe97 NSApplicationMain + 780
34 TodoDock 0x105173a99 main (AppDelegate.swift:18)
35 libdyld.dylib 0x7fff7fa7a085 start + 1


By the looks of it, it seems the app didn't event load yet.



I even managed to get to a guy that had the same issue, installed Xcode on his machine and run the same version locally, and everything worked!
Not only that but after I did, the downloaded app worked too! This is so strange, I really do not have a clue what is going on.
And more users are expirancing this, but not all of them.










share|improve this question
























  • Maybe a dangling pointer. Have you checked this thread ?
    – gulyashki
    Nov 24 at 16:09












  • @gulyashki yes I did. I want over all places that used blocks or delegates to check for memory leaks, and profiled for leaks, with none found. I do not really think this is the issue since it happens on load before the app is even shown.
    – MCMatan
    Nov 24 at 16:41













up vote
5
down vote

favorite









up vote
5
down vote

favorite











Trying to understand this crash for days now.



For some users (Randomly, operation systems 10.14/10.14.1) app crashes on the first load.



Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000
-[NSCollectionViewData layoutAttributesForItemAtIndexPath:]

Crashed: com.apple.main-thread
0 UIFoundation 0x7fff7ac71c6a -[NSCollectionViewData layoutAttributesForItemAtIndexPath:] + 72
1 UIFoundation 0x7fff7ac3cb52 -[_NSCollectionViewCore _updateVisibleCellsNow:] + 7748
2 UIFoundation 0x7fff7ac358a9 -[_NSCollectionViewCore _layoutItems] + 298
3 AppKit 0x7fff5019dbc2 -[NSCollectionView layout] + 360
4 AppKit 0x7fff5002e755 _NSViewLayout + 587
5 AppKit 0x7fff5002e0fc -[NSView _layoutSubtreeWithOldSize:] + 446
6 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
7 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
8 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
9 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
10 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
11 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
12 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
13 AppKit 0x7fff5002bb96 -[NSView _layoutSubtreeIfNeededAndAllowTemporaryEngine:] + 1358
14 AppKit 0x7fff5002b332 -[NSWindow(NSConstraintBasedLayout) _layoutViewTree] + 148
15 AppKit 0x7fff5003cfee -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 263
16 AppKit 0x7fff50041469 -[NSWindow displayIfNeeded] + 180
17 AppKit 0x7fff5004130f __NSWindowGetDisplayCycleObserverForDisplay_block_invoke + 722
18 AppKit 0x7fff5003c41a NSDisplayCycleObserverInvoke + 170
19 AppKit 0x7fff5003bf8f NSDisplayCycleFlush + 1073
20 QuartzCore 0x7fff5d9621d3 CA::Transaction::run_commit_handlers(CATransactionPhase) + 49
21 QuartzCore 0x7fff5d961b9a CA::Transaction::commit() + 186
22 AppKit 0x7fff5003b8f5 __65+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayRefresh]_block_invoke + 274
23 CoreFoundation 0x7fff52a3f95d __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
24 CoreFoundation 0x7fff52a3f892 __CFRunLoopDoObservers + 452
25 CoreFoundation 0x7fff529e13c5 __CFRunLoopRun + 1166
26 CoreFoundation 0x7fff529e0ce4 CFRunLoopRunSpecific + 463
27 HIToolbox 0x7fff51c7a895 RunCurrentEventLoopInMode + 293
28 HIToolbox 0x7fff51c7a5cb ReceiveNextEventCommon + 618
29 HIToolbox 0x7fff51c7a348 _BlockUntilNextEventMatchingListInModeWithFilter + 64
30 AppKit 0x7fff4ff3795b _DPSNextEvent + 997
31 AppKit 0x7fff4ff366fa -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1362
32 AppKit 0x7fff4ff3075d -[NSApplication run] + 699
33 AppKit 0x7fff4ff1fe97 NSApplicationMain + 780
34 TodoDock 0x105173a99 main (AppDelegate.swift:18)
35 libdyld.dylib 0x7fff7fa7a085 start + 1


By the looks of it, it seems the app didn't event load yet.



I even managed to get to a guy that had the same issue, installed Xcode on his machine and run the same version locally, and everything worked!
Not only that but after I did, the downloaded app worked too! This is so strange, I really do not have a clue what is going on.
And more users are expirancing this, but not all of them.










share|improve this question















Trying to understand this crash for days now.



For some users (Randomly, operation systems 10.14/10.14.1) app crashes on the first load.



Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000
-[NSCollectionViewData layoutAttributesForItemAtIndexPath:]

Crashed: com.apple.main-thread
0 UIFoundation 0x7fff7ac71c6a -[NSCollectionViewData layoutAttributesForItemAtIndexPath:] + 72
1 UIFoundation 0x7fff7ac3cb52 -[_NSCollectionViewCore _updateVisibleCellsNow:] + 7748
2 UIFoundation 0x7fff7ac358a9 -[_NSCollectionViewCore _layoutItems] + 298
3 AppKit 0x7fff5019dbc2 -[NSCollectionView layout] + 360
4 AppKit 0x7fff5002e755 _NSViewLayout + 587
5 AppKit 0x7fff5002e0fc -[NSView _layoutSubtreeWithOldSize:] + 446
6 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
7 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
8 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
9 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
10 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
11 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
12 AppKit 0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
13 AppKit 0x7fff5002bb96 -[NSView _layoutSubtreeIfNeededAndAllowTemporaryEngine:] + 1358
14 AppKit 0x7fff5002b332 -[NSWindow(NSConstraintBasedLayout) _layoutViewTree] + 148
15 AppKit 0x7fff5003cfee -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 263
16 AppKit 0x7fff50041469 -[NSWindow displayIfNeeded] + 180
17 AppKit 0x7fff5004130f __NSWindowGetDisplayCycleObserverForDisplay_block_invoke + 722
18 AppKit 0x7fff5003c41a NSDisplayCycleObserverInvoke + 170
19 AppKit 0x7fff5003bf8f NSDisplayCycleFlush + 1073
20 QuartzCore 0x7fff5d9621d3 CA::Transaction::run_commit_handlers(CATransactionPhase) + 49
21 QuartzCore 0x7fff5d961b9a CA::Transaction::commit() + 186
22 AppKit 0x7fff5003b8f5 __65+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayRefresh]_block_invoke + 274
23 CoreFoundation 0x7fff52a3f95d __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
24 CoreFoundation 0x7fff52a3f892 __CFRunLoopDoObservers + 452
25 CoreFoundation 0x7fff529e13c5 __CFRunLoopRun + 1166
26 CoreFoundation 0x7fff529e0ce4 CFRunLoopRunSpecific + 463
27 HIToolbox 0x7fff51c7a895 RunCurrentEventLoopInMode + 293
28 HIToolbox 0x7fff51c7a5cb ReceiveNextEventCommon + 618
29 HIToolbox 0x7fff51c7a348 _BlockUntilNextEventMatchingListInModeWithFilter + 64
30 AppKit 0x7fff4ff3795b _DPSNextEvent + 997
31 AppKit 0x7fff4ff366fa -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1362
32 AppKit 0x7fff4ff3075d -[NSApplication run] + 699
33 AppKit 0x7fff4ff1fe97 NSApplicationMain + 780
34 TodoDock 0x105173a99 main (AppDelegate.swift:18)
35 libdyld.dylib 0x7fff7fa7a085 start + 1


By the looks of it, it seems the app didn't event load yet.



I even managed to get to a guy that had the same issue, installed Xcode on his machine and run the same version locally, and everything worked!
Not only that but after I did, the downloaded app worked too! This is so strange, I really do not have a clue what is going on.
And more users are expirancing this, but not all of them.







swift macos macos-mojave






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 at 10:51









Rengers

7,72012343




7,72012343










asked Nov 22 at 14:48









MCMatan

3,0532151




3,0532151












  • Maybe a dangling pointer. Have you checked this thread ?
    – gulyashki
    Nov 24 at 16:09












  • @gulyashki yes I did. I want over all places that used blocks or delegates to check for memory leaks, and profiled for leaks, with none found. I do not really think this is the issue since it happens on load before the app is even shown.
    – MCMatan
    Nov 24 at 16:41


















  • Maybe a dangling pointer. Have you checked this thread ?
    – gulyashki
    Nov 24 at 16:09












  • @gulyashki yes I did. I want over all places that used blocks or delegates to check for memory leaks, and profiled for leaks, with none found. I do not really think this is the issue since it happens on load before the app is even shown.
    – MCMatan
    Nov 24 at 16:41
















Maybe a dangling pointer. Have you checked this thread ?
– gulyashki
Nov 24 at 16:09






Maybe a dangling pointer. Have you checked this thread ?
– gulyashki
Nov 24 at 16:09














@gulyashki yes I did. I want over all places that used blocks or delegates to check for memory leaks, and profiled for leaks, with none found. I do not really think this is the issue since it happens on load before the app is even shown.
– MCMatan
Nov 24 at 16:41




@gulyashki yes I did. I want over all places that used blocks or delegates to check for memory leaks, and profiled for leaks, with none found. I do not really think this is the issue since it happens on load before the app is even shown.
– MCMatan
Nov 24 at 16:41












1 Answer
1






active

oldest

votes

















up vote
6
down vote



accepted
+50










I had the same problem of random crashes at the start.



Possible reasons:




  1. CollectionViewItem with different size


  2. viewFor() called before the view is even loaded (Happens when switching or changing or editing the views)


  3. Editing the size of one collection view item affecting the other collection view item(possible if the former is removed)



I fixed it by adding if condition to check whether the collection view is nil or not. Also by checking whether the datasource numberOfItems is consistent when changing the views.






share|improve this answer























  • You are correct. I was actually using "select" setter of CollectionViewItem to trigger some logic, which had a side effect of selecting collection view items before it was created. Thank you.
    – MCMatan
    Nov 29 at 10:26










  • You're welcome @MCMatan
    – mouseymaniac
    Nov 29 at 13:37













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433430%2fcrash-nscollectionviewdata-layoutattributesforitematindexpath%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
6
down vote



accepted
+50










I had the same problem of random crashes at the start.



Possible reasons:




  1. CollectionViewItem with different size


  2. viewFor() called before the view is even loaded (Happens when switching or changing or editing the views)


  3. Editing the size of one collection view item affecting the other collection view item(possible if the former is removed)



I fixed it by adding if condition to check whether the collection view is nil or not. Also by checking whether the datasource numberOfItems is consistent when changing the views.






share|improve this answer























  • You are correct. I was actually using "select" setter of CollectionViewItem to trigger some logic, which had a side effect of selecting collection view items before it was created. Thank you.
    – MCMatan
    Nov 29 at 10:26










  • You're welcome @MCMatan
    – mouseymaniac
    Nov 29 at 13:37

















up vote
6
down vote



accepted
+50










I had the same problem of random crashes at the start.



Possible reasons:




  1. CollectionViewItem with different size


  2. viewFor() called before the view is even loaded (Happens when switching or changing or editing the views)


  3. Editing the size of one collection view item affecting the other collection view item(possible if the former is removed)



I fixed it by adding if condition to check whether the collection view is nil or not. Also by checking whether the datasource numberOfItems is consistent when changing the views.






share|improve this answer























  • You are correct. I was actually using "select" setter of CollectionViewItem to trigger some logic, which had a side effect of selecting collection view items before it was created. Thank you.
    – MCMatan
    Nov 29 at 10:26










  • You're welcome @MCMatan
    – mouseymaniac
    Nov 29 at 13:37















up vote
6
down vote



accepted
+50







up vote
6
down vote



accepted
+50




+50




I had the same problem of random crashes at the start.



Possible reasons:




  1. CollectionViewItem with different size


  2. viewFor() called before the view is even loaded (Happens when switching or changing or editing the views)


  3. Editing the size of one collection view item affecting the other collection view item(possible if the former is removed)



I fixed it by adding if condition to check whether the collection view is nil or not. Also by checking whether the datasource numberOfItems is consistent when changing the views.






share|improve this answer














I had the same problem of random crashes at the start.



Possible reasons:




  1. CollectionViewItem with different size


  2. viewFor() called before the view is even loaded (Happens when switching or changing or editing the views)


  3. Editing the size of one collection view item affecting the other collection view item(possible if the former is removed)



I fixed it by adding if condition to check whether the collection view is nil or not. Also by checking whether the datasource numberOfItems is consistent when changing the views.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 26 at 6:59

























answered Nov 26 at 5:49









mouseymaniac

1915




1915












  • You are correct. I was actually using "select" setter of CollectionViewItem to trigger some logic, which had a side effect of selecting collection view items before it was created. Thank you.
    – MCMatan
    Nov 29 at 10:26










  • You're welcome @MCMatan
    – mouseymaniac
    Nov 29 at 13:37




















  • You are correct. I was actually using "select" setter of CollectionViewItem to trigger some logic, which had a side effect of selecting collection view items before it was created. Thank you.
    – MCMatan
    Nov 29 at 10:26










  • You're welcome @MCMatan
    – mouseymaniac
    Nov 29 at 13:37


















You are correct. I was actually using "select" setter of CollectionViewItem to trigger some logic, which had a side effect of selecting collection view items before it was created. Thank you.
– MCMatan
Nov 29 at 10:26




You are correct. I was actually using "select" setter of CollectionViewItem to trigger some logic, which had a side effect of selecting collection view items before it was created. Thank you.
– MCMatan
Nov 29 at 10:26












You're welcome @MCMatan
– mouseymaniac
Nov 29 at 13:37






You're welcome @MCMatan
– mouseymaniac
Nov 29 at 13:37




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433430%2fcrash-nscollectionviewdata-layoutattributesforitematindexpath%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

Alexandru Averescu

Trompette piccolo