Crash when sorting tree bound to NSOutlineView
Crash when sorting tree bound to NSOutlineView
- Subject: Crash when sorting tree bound to NSOutlineView
- From: Markus Spoettl <email@hidden>
- Date: Sat, 27 Dec 2008 11:19:22 -0800
Hi All,
I have a problem with an NSOutlineView which crashes deep in the
framework (full stack below). The tree structure is bound to the
outline and all operations including sort are done on arrays obtained
by using -mutableArrayValueForKey: on the respective sub-tree array.
Up until now I didn't have any trouble with it but I guess the first
question is: Can I sort a bound tree that way, is it supposed to work?
This is my recursive sort method in the node class, pretty simple:
- (void)sort
{
NSMutableArray *kvoNodes = [self mutableArrayValueForKey:@"nodes"];
[kvoNodes sortUsingSelector:@selector(compare:)];
for (ActivityGroupNode *node in nodes) {
[node sort];
}
}
The interesting thing is that if I turn it around sorting depth first
like this
- (void)sort
{
for (ActivityGroupNode *node in nodes) {
[node sort];
}
NSMutableArray *kvoNodes = [self mutableArrayValueForKey:@"nodes"];
[kvoNodes sortUsingSelector:@selector(compare:)];
}
The crash goes away. However, I have a feeling that this may be pure
coincidence. Even more so as the crash also goes way if the node
inserted is not on that particular location in the tree or if another
node gets inserted somewhere else first. All very strange.
Could someone please confirm that I can or cannot sort a bound tree
like that? I'm using Xcode 3.1.2 and Mac OS X 10.5.6.
Regards
Markus
-----------------------------------------------------------------------------------
Prior to this the tree exists and is being displayed by the
NSOutlineView.
1) A new sub-node gets added to a leaf node on level 2 (first of its
siblings)
2) The whole tree is sorted via a call to -sort on the root node.
N
- N
- N
- N
N
- N <--------- new child added here
- N
- N
- N
- N
- N
N
...
#0 0x947bf688 in objc_msgSend
#1 0x91ce9cdf in -[NSConcreteHashTable assign:key:]
#2 0x91ce9ada in -[NSConcreteHashTable addObject:]
#3 0x94efb83c in -[_NSTreeNodeObservingTracker
_startObservingModelObject:]
#4 0x94dd6d52 in -[NSOutlineViewBinder outlineView:isItemExpandable:]
#5 0x94ef8740 in -[_NSBindingAdaptor boundOutlineView:isItemExpandable:]
#6 0x9495caf0 in -[NSOutlineView _dataSourceIsItemExpandable:]
#7 0x9495c9a2 in loadItemEntryLazyInfoIfNecessary
#8 0x9495c779 in -[NSOutlineView itemAtRow:]
#9 0x94aba275 in -[NSOutlineView _delegate_isGroupRow:]
#10 0x9495f994 in -[NSTableView _isGroupRow:]
#11 0x94aba1d8 in -[NSOutlineView _sendDelegateHeightOfRow:]
#12 0x94ab9fbb in -[NSTableView _uncachedRectHeightOfRow:]
#13 0x94abace4 in -[_NSTableRowHeightStorage
_convert:row:point:cacheHint:]
#14 0x94aba999 in -[_NSTableRowHeightStorage
_computeOriginForRow:cacheHint:]
#15 0x94aba8aa in -[_NSTableRowHeightStorage
computeRectOfRow:cacheHint:]
#16 0x94aba7cd in -[NSTableView
_rowHeightStorageComputeRectOfRow:cacheHint:]
#17 0x9495daf6 in -[NSTableView _rectOfRowAssumingRowExists:]
#18 0x9495da20 in -[NSTableView rectOfRow:]
#19 0x9495d860 in -[NSOutlineView rectOfRow:]
#20 0x94dd62ae in -[NSOutlineViewBinder
observeValueForKeyPath:ofObject:change:context:]
#21 0x91d63b0e in NSKVONotify
#22 0x91cdffd2 in -[NSObject(NSKeyValueObserverNotification)
didChangeValueForKey:]
#23 0x94f747af in -[NSTreeControllerTreeNode
updateChildNodesForKeyPath:]
#24 0x94f72e0c in -[NSTreeControllerTreeNode
observeValueForKeyPath:ofObject:change:context:]
#25 0x91d63b0e in NSKVONotify
#26 0x91d73ce2 in -[NSObject(NSKeyValueObserverNotification)
didChange:valuesAtIndexes:forKey:]
#27 0x91e13574 in -[NSKeyValueNotifyingMutableArray
replaceObjectAtIndex:withObject:]
#28 0x91dce381 in -[NSMutableArray(NSMutableArray)
sortUsingFunction:context:]
#29 0x91d1759f in -[NSMutableArray(NSMutableArray) sortUsingSelector:]
#30 0x0004548d in -[ActivityGroupNode sort] at ActivityGroups.m:466
#31 0x00045542 in -[ActivityGroupNode sort] at ActivityGroups.m:469
#32 0x0004905a in -[ActivityGroups makeGroupsForActivities:] at
ActivityGroups.m:1176
#33 0x0001b749 in -[RubiData addManualActivity:] at RubiData.m:3494
#34 0x00082e9d in -[NewActivitySheetController
didEndSheet:returnCode:contextInfo:] at NewActivitySheetController.m:70
#35 0x949df233 in -[NSApplication endSheet:returnCode:]
#36 0x00083006 in -[NewActivitySheetController doneAddingActivity:] at
NewActivitySheetController.m:90
#37 0x9499d53b in -[NSApplication sendAction:to:from:]
#38 0x9499d478 in -[NSControl sendAction:to:]
#39 0x9499d2fe in -[NSCell _sendActionFrom:]
#40 0x9499c957 in -[NSCell trackMouse:inRect:ofView:untilMouseUp:]
#41 0x9499c1aa in -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:]
#42 0x9499ba64 in -[NSControl mouseDown:]
#43 0x9499a1a3 in -[NSWindow sendEvent:]
#44 0x94966d49 in -[NSApplication sendEvent:]
#45 0x948c469f in -[NSApplication run]
#46 0x948918a4 in NSApplicationMain
#47 0x0000576c in main at main.m:13
--
__________________________________________
Markus Spoettl
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden