Re: TableView crash with Delegate

2016-06-14 Thread Jonathan Mitchell

> On 14 Jun 2016, at 12:26, Gerriet M. Denkmann  wrote:
> 
> 
> But no problem, as long one keeps in mind (as you recommended) that 
> awakeFromNib “can get called many times”.
> 
You may be experiencing this, as described in docs for view based table views:

NSTableView - (__kindofNSView 

 *)makeViewWithIdentifier:(NSString 

 *)identifier
 owner:(id)owner

This method is usually called by the delegate in 
tableView:viewForTableColumn:row: 
,
 but it can also be overridden to provide custom views for the identifier. Note 
that awakeFromNib 

 is called each time this method is called, which means that awakeFromNib is 
also called on owner, even though the owner is already awake.

This has thrown me for loop in the past - especially when the above note was 
only in the headers.

J

> 
> Kind regards,
> 
> Gerriet.
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/lists%40mugginsoft.com
> 
> This email sent to li...@mugginsoft.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: TableView crash with Delegate

2016-06-14 Thread Gerriet M. Denkmann

> On 14 Jun 2016, at 16:03, Alastair Houghton  
> wrote:
> 
> On 14 Jun 2016, at 05:33, Gerriet M. Denkmann  wrote:
>> 
>> But I had:
>> - (void)awakeFromNib 
>> {
>>  self.someUniqueObject = [ [ UniqueObject alloc ] init ];
>> }
>> 
>> The problem: awakeFromNib gets called twice: once before 
>> applicationDidFinishLaunching:, once after.
>> This obviously created a total mess.
> 
> It’s worth highlighting this, actually; -awakeFromNib gets called for the 
> “File’s Owner” object in the nib file, which means if your object has 
> multiple nib files associated with it, it can get called many times.  It’s 
> best (IMO) to always write your -awakeFromNib methods with that in mind 
> (though the documentation recommends trying to maintain a 1:1 correspondence 
> between owners and nib files).

There is just one nib file, owned by (“File’s Owner”) NSApplication.
It contains (among other things) an AppDelegate, referenced as “File’s 
Owner”.delegate and a (view based) TableView.

AppDelegate is not the “File’s Owner” of any nib.

awakeFromNib in AppDelegate is first called (as one of the topLevelObjects in 
the nib) via:
NSApplicationMain → … loadNib … → [NSSet makeObjectsPerform:]

After applicationDidFinishLaunching awakeFromNib is called again, this time 
via: 
NSApplicationMain → [NSApplication run] → [NSWindow layoutIfNeeded] … → 
[NSTableView layout] …→[NSTableRowData unarchiveView…] → [NSNib 
instantiateWithOwner] …

The documentation says: “You might also want to implement [awakeFromNib] for 
any other classes you instantiate directly in your nib file“, which probably 
means the topLevelObjects, like my AppDelegate.

But it does not mention whether these topLevelObjects get awakeFromNib sent 
only once or not.

But no problem, as long one keeps in mind (as you recommended) that 
awakeFromNib “can get called many times”.


Kind regards,

Gerriet.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: TableView crash with Delegate

2016-06-14 Thread Alastair Houghton
On 14 Jun 2016, at 05:33, Gerriet M. Denkmann  wrote:
> 
> But I had:
> - (void)awakeFromNib 
> {
>   self.someUniqueObject = [ [ UniqueObject alloc ] init ];
> }
> 
> The problem: awakeFromNib gets called twice: once before 
> applicationDidFinishLaunching:, once after.
> This obviously created a total mess.

It’s worth highlighting this, actually; -awakeFromNib gets called for the 
“File’s Owner” object in the nib file, which means if your object has multiple 
nib files associated with it, it can get called many times.  It’s best (IMO) to 
always write your -awakeFromNib methods with that in mind (though the 
documentation recommends trying to maintain a 1:1 correspondence between owners 
and nib files).

Kind regards,

Alastair.

--
http://alastairs-place.net


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: TableView crash with Delegate

2016-06-13 Thread Gerriet M. Denkmann

> On 13 Jun 2016, at 21:43, Alastair Houghton  
> wrote:
> 
> On 12 Jun 2016, at 10:10, Gerriet M. Denkmann  wrote:
>> 
>> OS X 10.11.5, Xcode Version 7.3.1 (7D1014).
>> 
>> App with TableView (View based). Works fine. 
>> But when I give the TableView a delegate (even without implementing any 
>> NSTableViewDelegate methods) it crashes (see below).
>> 
>> How to debug this?
>> Tried a symbolic breakpoint in  -[__NSArrayM objectAtIndex:] - but it 
>> crashes before reaching breakpoint.
> 
> Set it to break on exceptions (or put a breakpoint on objc_exception_throw), 
> then go back up the call stack?

This ultimately let me to the root of the problem:

My app has only one TableView, which is bound to Array Controller.
Array Controller binds its Content Array to AppDelegate with Model Key Path 
self.someUniqueObject.aMutableArray.
When the app starts a unique someUniqueObject gets created.

But I had:
- (void)awakeFromNib 
{
self.someUniqueObject = [ [ UniqueObject alloc ] init ];
}

The problem: awakeFromNib gets called twice: once before 
applicationDidFinishLaunching:, once after.
This obviously created a total mess.

Solution: move the creation of someUniqueObject to 
applicationDidFinishLaunching:


Thanks for your help!

Kind regards,

Gerriet.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: TableView crash with Delegate

2016-06-13 Thread Alastair Houghton
On 12 Jun 2016, at 10:10, Gerriet M. Denkmann  wrote:
> 
> OS X 10.11.5, Xcode Version 7.3.1 (7D1014).
> 
> App with TableView (View based). Works fine. 
> But when I give the TableView a delegate (even without implementing any 
> NSTableViewDelegate methods) it crashes (see below).
> 
> How to debug this?
> Tried a symbolic breakpoint in  -[__NSArrayM objectAtIndex:] - but it crashes 
> before reaching breakpoint.

Set it to break on exceptions (or put a breakpoint on objc_exception_throw), 
then go back up the call stack?

Alternatively, if that isn’t helpful (and it might well not be), I’d start 
looking to see whether I was doing anything I shouldn’t; for instance, changing 
the number of items in the table view from a data source or delegate method 
where doing that isn't safe.  Not sure how much of that is documented; some of 
it might be assumed to be “obvious”.  Pretty sure I’ve crashed NSTableView 
before that way, and with an index beyond bounds error at that.

Kind regards,

Alastair.

--
http://alastairs-place.net
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

TableView crash with Delegate

2016-06-12 Thread Gerriet M. Denkmann
OS X 10.11.5, Xcode Version 7.3.1 (7D1014).

App with TableView (View based). Works fine. 
But when I give the TableView a delegate (even without implementing any 
NSTableViewDelegate methods) it crashes (see below).

How to debug this?
Tried a symbolic breakpoint in  -[__NSArrayM objectAtIndex:] - but it crashes 
before reaching breakpoint.


2016-06-12 15:26:36.172 Echo App[24004:2898793] *** -[__NSArrayM 
objectAtIndex:]: index 0 beyond bounds for empty array
2016-06-12 15:26:36.175 Echo App[24004:2898793] (
0   CoreFoundation  0x7fff8a3904f2 
__exceptionPreprocess + 178
1   libobjc.A.dylib 0x7fff880d873c 
objc_exception_throw + 48
2   CoreFoundation  0x7fff8a2a77c5 -[__NSArrayM 
objectAtIndex:] + 245
3   AppKit  0x7fff9a3dad31 
-[NSTableRowData _addViewToRowView:atColumn:row:] + 535
4   AppKit  0x7fff9a3da98e 
-[NSTableRowData _addViewsToRowView:atRow:] + 184
5   AppKit  0x7fff9a3d91a7 
-[NSTableRowData _initializeRowView:atRow:] + 390
6   AppKit  0x7fff9a3d7907 
-[NSTableRowData _addRowViewForVisibleRow:withPriorView:] + 416
7   AppKit  0x7fff9a3d769b 
-[NSTableRowData 
_addRowViewForVisibleRow:withPriorRowIndex:inDictionary:withRowAnimation:] + 299
8   AppKit  0x7fff9a3d6461 
-[NSTableRowData _unsafeUpdateVisibleRowEntries] + 1697
9   AppKit  0x7fff9a3d5d22 
-[NSTableRowData updateVisibleRowViews] + 233
10  AppKit  0x7fff9a3d569b 
-[NSTableView layout] + 178
11  AppKit  0x7fff9a3743e7 -[NSView 
_doLayout] + 53
12  AppKit  0x7fff9a37409f -[NSView 
_layoutSubtreeWithOldSize:] + 324
13  AppKit  0x7fff9a3742fb -[NSView 
_layoutSubtreeWithOldSize:] + 928
14  AppKit  0x7fff9a3742fb -[NSView 
_layoutSubtreeWithOldSize:] + 928
15  AppKit  0x7fff9a3742fb -[NSView 
_layoutSubtreeWithOldSize:] + 928
16  AppKit  0x7fff9a3742fb -[NSView 
_layoutSubtreeWithOldSize:] + 928
17  AppKit  0x7fff9a3735d8 -[NSView 
layoutSubtreeIfNeeded] + 950
18  AppKit  0x7fff9a392f21 
-[NSWindow(NSConstraintBasedLayout) _layoutViewTree] + 82
19  AppKit  0x7fff9a4054ff 
-[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 244
20  AppKit  0x7fff9aa9c155 
___NSWindowGetDisplayCycleObserver_block_invoke6358 + 218
21  AppKit  0x7fff9a4174f8 
__37+[NSDisplayCycle currentDisplayCycle]_block_invoke + 719
22  QuartzCore  0x7fff8f413f71 
_ZN2CA11Transaction19run_commit_handlersE18CATransactionPhase + 85
23  QuartzCore  0x7fff8f41342c 
_ZN2CA7Context18commit_transactionEPNS_11TransactionE + 160
24  QuartzCore  0x7fff8f4130ec 
_ZN2CA11Transaction6commitEv + 508
25  QuartzCore  0x7fff8f41e977 
_ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 71
26  CoreFoundation  0x7fff8a325067 
__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
27  CoreFoundation  0x7fff8a324fd7 
__CFRunLoopDoObservers + 391
28  CoreFoundation  0x7fff8a303ef8 
CFRunLoopRunSpecific + 328
29  HIToolbox   0x7fff97834935 
RunCurrentEventLoopInMode + 235
30  HIToolbox   0x7fff97834677 
ReceiveNextEventCommon + 184
31  HIToolbox   0x7fff978345af 
_BlockUntilNextEventMatchingListInModeWithFilter + 71
32  AppKit  0x7fff9a2bfdf6 
_DPSNextEvent + 1067
33  AppKit  0x7fff9a2bf226 
-[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
34  AppKit  0x7fff9a2b3d80 
-[NSApplication run] + 682
35  AppKit  0x7fff9a27d368 
NSApplicationMain + 1176
36  Echo App0x00013202 main + 34
37  libdyld.dylib   0x7fff887695ad start + 1
)
2016-06-12 15:26:36.314 Echo App[24004:2898793] -[NSApplication 
runModalForWindow:] may not be invoked inside of transaction commit (usually 
this means it was invoked inside of a view's -drawRect: method.)