crash in outlineView:isGroupItem:
crash in outlineView:isGroupItem:
- Subject: crash in outlineView:isGroupItem:
- From: Joan Lluch (casa) <email@hidden>
- Date: Mon, 9 Jun 2008 00:02:58 +0200
I am using outlineView:isGroupItem delegate method to create an
NSOutlineView that mimics the look of Mail.app or iTunes
- (BOOL)outlineView:(NSOutlineView *)sender isGroupItem:(id)item
{
return ( item && [[item representedObject] isKindOfClass:
[GroupNode class]] ) ;
}
My oulineView is binded to a treeController that in turn is binded
to Core Data objects. The visual result is as expected and
everything goes ok. When I add hierarchical objects to the
managedObjectContext they correctly appear in the outlineView as
expected. So far so good.
However, I observed that isGroupItem is called a lot more than
apparently necessary, and I did not not observe any clear pattern
for this. It is usually called as much as 20 or more times per
item, in no particular order and also interlacing calls for
different items. This should not be a big issue as far as the app
remains responsible, although I find it hard to understand why
isGroupItem does behave that way.
On the contrary, outlineView:willDisplayCell (below) behaves in a
completely consistent way, as it is being called exactly column
times for each row.
- (void)outlineView:(NSOutlineView *)sender willDisplayCell:
(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
The problem with isGroupItem is that it crashes the app (also not
consistently) after several Undos performed on the
managedObjectContext (to remove recently added objects) as it is
eventually called with an already released "item". I do not
understand it and I do not either know what to do or what to check
in order to avoid this. Since my app relies on bindings and Core
Data it has not a lot of code, and I am not able to find anything
wrong in it.
Any help or hint to solve that issue will be appreciated.
Follow up:
Only by setting the highlight property of the outlineView to
"Regular" instead of "Source List" in IB all the problems were
solved. Now isGroupItem is only called a reasonable amount of times,
and the app no longer crashes. Of course, the visual aspect of the
outlineView is not the intended one though.
The problem can be partially reproduced in the DragNDropOutlineView
example project by setting "Source List" in IB for the outlineView
highlight property. You can also add an NSLog to the isGroupItem
method to clearly see how many times it is called. However, the app
does not crash when the items are trashed.
So, the crash apparently only happens in an app which uses Core Data
as the model source, and while undoing recently added items. Would
someone confirm this so I will issue a bug report to Apple?. In the
meantime, I will look whether I can easily reproduce it in any of
the examples provided by Apple.
Thanks.
Ok, I did it. This is now a confirmed bug. To reproduce it:
Modify the OutlineEdit example as follows:
1- In IB add set the "highlight" property of the outlineView to
"Source List"
2- In IB set the delegate of the outlineView to the "owner" (the
document in this case)
3- Add the following method to myDocument.m
- (BOOL)outlineView:(NSOutlineView *)sender isGroupItem:(id)item
{
NSLog( @"item: %@", item) ;
return NO ;
}
Then compile and run the app. In the running OutlineEdit.app do the
following:
1- add a new child by pressing "new Child" or using the main menu.
2- select a different node than the one created in step 1
3- choose "undo" in the main menu.
Voila! : the app crashes in isGroupItem with EXC_BAD_ACCESS.
_______________________________________________
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