Strange RunTime Error


#1

This may be a compiler error, an Xcode error or… well I am not sure. When adding a binding, say the label part in pages 120-121 the first time the application is run, it terminates with a call to -[KvcFunAppDelegate copyWithZone:]: unrecognized selector sent to instance 0x1004343e0. If I kill the run and then immediately run it again, it works as expected. This is repeatable by removing the label, then running the app, stopping it, re-adding the label and setting the binding again; once again on he initial compile and run the error occurs. Is this something I’m doing or not doing or is this possibly a bug in the compiler, the OS, or where? What I don’t get is why is it an error only on the first run?

Below is the entire error Console log for this:

2011-11-25 10:03:54.873 KvcFun[19124:707] -setFido: is called with 5 2011-11-25 10:03:54.874 KvcFun[19124:707] -fido is returning 5 2011-11-25 10:03:54.919 KvcFun[19124:707] fido = 5 2011-11-25 10:03:54.926 KvcFun[19124:707] -[KvcFunAppDelegate copyWithZone:]: unrecognized selector sent to instance 0x1004343e0 2011-11-25 10:03:54.927 KvcFun[19124:707] An uncaught exception was raised 2011-11-25 10:03:54.927 KvcFun[19124:707] -[KvcFunAppDelegate copyWithZone:]: unrecognized selector sent to instance 0x1004343e0 2011-11-25 10:03:54.931 KvcFun[19124:707] ( 0 CoreFoundation 0x00007fff895ad286 __exceptionPreprocess + 198 1 libobjc.A.dylib 0x00007fff8bdcad5e objc_exception_throw + 43 2 CoreFoundation 0x00007fff896394ce -[NSObject doesNotRecognizeSelector:] + 190 3 CoreFoundation 0x00007fff8959a133 ___forwarding___ + 371 4 CoreFoundation 0x00007fff89599f48 _CF_forwarding_prep_0 + 232 5 AppKit 0x00007fff8e1be5dc -[NSCell _setContents:] + 73 6 AppKit 0x00007fff8e1be4b9 -[NSCell setObjectValue:] + 160 7 AppKit 0x00007fff8e3cccd4 -[NSControl setObjectValue:] + 115 8 AppKit 0x00007fff8e3e17bc -[_NSPlaceholderTextFieldPlugin showValue:inObject:] + 388 9 AppKit 0x00007fff8e3c9b45 -[NSValueBinder _adjustObject:mode:observedController:observedKeyPath:context:editableState:adjustState:] + 809 10 AppKit 0x00007fff8e3c9788 -[NSValueBinder _observeValueForKeyPath:ofObject:context:] + 303 11 AppKit 0x00007fff8e3e15af -[NSTextValueBinder _observeValueForKeyPath:ofObject:context:] + 43 12 AppKit 0x00007fff8e1b7bdb -[NSObject(NSKeyValueBindingCreation) bind:toObject:withKeyPath:options:] + 591 13 AppKit 0x00007fff8e1b0ef5 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1079 14 AppKit 0x00007fff8e1a752f loadNib + 322 15 AppKit 0x00007fff8e1a6a28 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 217 16 AppKit 0x00007fff8e1a6943 +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 141 17 AppKit 0x00007fff8e1a6886 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 364 18 AppKit 0x00007fff8e41a637 NSApplicationMain + 398 19 KvcFun 0x0000000100001462 main + 34 20 KvcFun 0x0000000100001434 start + 52 ) 2011-11-25 10:03:54.935 KvcFun[19124:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[KvcFunAppDelegate copyWithZone:]: unrecognized selector sent to instance 0x1004343e0' *** First throw call stack: ( 0 CoreFoundation 0x00007fff895ad286 __exceptionPreprocess + 198 1 libobjc.A.dylib 0x00007fff8bdcad5e objc_exception_throw + 43 2 CoreFoundation 0x00007fff896394ce -[NSObject doesNotRecognizeSelector:] + 190 3 CoreFoundation 0x00007fff8959a133 ___forwarding___ + 371 4 CoreFoundation 0x00007fff89599f48 _CF_forwarding_prep_0 + 232 5 AppKit 0x00007fff8e1be5dc -[NSCell _setContents:] + 73 6 AppKit 0x00007fff8e1be4b9 -[NSCell setObjectValue:] + 160 7 AppKit 0x00007fff8e3cccd4 -[NSControl setObjectValue:] + 115 8 AppKit 0x00007fff8e3e17bc -[_NSPlaceholderTextFieldPlugin showValue:inObject:] + 388 9 AppKit 0x00007fff8e3c9b45 -[NSValueBinder _adjustObject:mode:observedController:observedKeyPath:context:editableState:adjustState:] + 809 10 AppKit 0x00007fff8e3c9788 -[NSValueBinder _observeValueForKeyPath:ofObject:context:] + 303 11 AppKit 0x00007fff8e3e15af -[NSTextValueBinder _observeValueForKeyPath:ofObject:context:] + 43 12 AppKit 0x00007fff8e1b7bdb -[NSObject(NSKeyValueBindingCreation) bind:toObject:withKeyPath:options:] + 591 13 AppKit 0x00007fff8e1b0ef5 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1079 14 AppKit 0x00007fff8e1a752f loadNib + 322 15 AppKit 0x00007fff8e1a6a28 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 217 16 AppKit 0x00007fff8e1a6943 +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 141 17 AppKit 0x00007fff8e1a6886 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 364 18 AppKit 0x00007fff8e41a637 NSApplicationMain + 398 19 KvcFun 0x0000000100001462 main + 34 20 KvcFun 0x0000000100001434 start + 52 ) terminate called throwing an exceptionsharedlibrary apply-load-rules all


#2

The exception you are seeing is almost certainly due to the text field (label) being bound to KvcFunAppDelegate with an empty Model Key Path, or a path of “self”. We can tell this because the exception says that copyWithZone: is being sent to KvcFunAppDelegate, which tells us that it’s trying to make a copy of the app delegate in order to display it in the label – not what we want to happen. :slight_smile: Fixing the Model Key Path should set you on the right path.

As for the exception only happening on the first run, I wasn’t able to reproduce this part. My guess is that it could have something to do with Lion’s UI preservation, but that doesn’t entirely explain what’s going on.

Adam


#3

Adam,

Thanks for looking and going by what you said I sat here a played with it for about 15 minutes and finally discovered the problem. It appears that if you don’t leave the “Model Key Path” field after selecting the proper data point (in this case “id fido”) it doesn’t recognize that you actually chose the data point; so it is seeing “self”, as your post indicated. When you run it again the IDE “sees” the change in the field (since when you run it it “defocuses”) and does a quick recompile and there it is. I was missing the fact that it was recompiling on that second run, even though I had not changed anything.

This is actually an Xcode bug but a pretty small one and easily worked around by remembering to actually leave any field that you enter something in before you attempt a save & compile.

Lou


#4

I am also getting an error but it is somewhat different. I should mention that I have Mountain Lion 10.8 and XCode 4.4.

I have set an Exception Breakpoint and when I start the Run it stops in main.m at the statement

return NSApplicationMain(argc, (const char **)argv);

and it says at the end of the line “Thread 1: breakpoint 1.1”. I then press Continue program execution and it says “Thread 1: breakpoint 1.2” and after I press Continue program execution it says “Thread 1: signal SIGABRT”.

In the Output Section I get the following:

2012-07-27 13:08:04.405 KvcFun[2208:303] -setFido: is called with 5
2012-07-27 13:08:04.406 KvcFun[2208:303] _fido is returning 5
2012-07-27 13:08:04.407 KvcFun[2208:303] fido = 5
2012-07-27 13:08:04.412 KvcFun[2208:303] _fido is returning 5
2012-07-27 13:08:13.785 KvcFun[2208:303] An uncaught exception was raised
2012-07-27 13:08:13.786 KvcFun[2208:303] Cannot create BOOL from object <KvcFunAppDelegate: 0x100150ad0> of class KvcFunAppDelegate
2012-07-27 13:08:13.790 KvcFun[2208:303] (
0 CoreFoundation 0x00007fff920c1716 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff9192b470 objc_exception_throw + 43
2 CoreFoundation 0x00007fff920c1558 +[NSException raise:format:arguments:] + 104
3 AppKit 0x00007fff8b556fb6 _NSBoolFromValue + 424
4 AppKit 0x00007fff8b55a35d -[NSEditableBinder enabledState] + 81
5 AppKit 0x00007fff8b55a2e7 -[NSEditableBinder _enabledStateWithMode:] + 44
6 AppKit 0x00007fff8b5564ca -[NSEditableBinder _setStatesImmediatelyInObject:mode:triggerRedisplay:] + 382
7 AppKit 0x00007fff8b55a125 -[NSEditorBinder _noticeEditablePeerBinder:] + 330
8 AppKit 0x00007fff8b55515f -[NSEditableBinder _synchronizeWithPeerBindersInArray:] + 149
9 AppKit 0x00007fff8b555005 -[NSBinder _updateDependenciesWithPeerBinders:] + 201
10 AppKit 0x00007fff8b554c2b -[NSBinder establishConnection] + 233
11 AppKit 0x00007fff8b54df49 -[NSObject(NSKeyValueBindingCreation) bind:toObject:withKeyPath:options:] + 641
12 AppKit 0x00007fff8b3d6afa -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1012
13 AppKit 0x00007fff8b3b5b7d loadNib + 317
14 AppKit 0x00007fff8b3b50a9 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 219
15 AppKit 0x00007fff8b3b4ede -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 200
16 AppKit 0x00007fff8b3b4cbe +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 360
17 AppKit 0x00007fff8b3b147f NSApplicationMain + 398
18 KvcFun 0x0000000100001132 main + 34
19 KvcFun 0x0000000100001104 start + 52
20 ??? 0x0000000000000003 0x0 + 3
)
2012-07-27 13:08:13.800 KvcFun[2208:303] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Cannot create BOOL from object <KvcFunAppDelegate: 0x100150ad0> of class KvcFunAppDelegate’
*** First throw call stack:
(
0 CoreFoundation 0x00007fff920c1716 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff9192b470 objc_exception_throw + 43
2 CoreFoundation 0x00007fff920c1558 +[NSException raise:format:arguments:] + 104
3 AppKit 0x00007fff8b556fb6 _NSBoolFromValue + 424
4 AppKit 0x00007fff8b55a35d -[NSEditableBinder enabledState] + 81
5 AppKit 0x00007fff8b55a2e7 -[NSEditableBinder _enabledStateWithMode:] + 44
6 AppKit 0x00007fff8b5564ca -[NSEditableBinder _setStatesImmediatelyInObject:mode:triggerRedisplay:] + 382
7 AppKit 0x00007fff8b55a125 -[NSEditorBinder _noticeEditablePeerBinder:] + 330
8 AppKit 0x00007fff8b55515f -[NSEditableBinder _synchronizeWithPeerBindersInArray:] + 149
9 AppKit 0x00007fff8b555005 -[NSBinder _updateDependenciesWithPeerBinders:] + 201
10 AppKit 0x00007fff8b554c2b -[NSBinder establishConnection] + 233
11 AppKit 0x00007fff8b54df49 -[NSObject(NSKeyValueBindingCreation) bind:toObject:withKeyPath:options:] + 641
12 AppKit 0x00007fff8b3d6afa -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1012
13 AppKit 0x00007fff8b3b5b7d loadNib + 317
14 AppKit 0x00007fff8b3b50a9 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 219
15 AppKit 0x00007fff8b3b4ede -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 200
16 AppKit 0x00007fff8b3b4cbe +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 360
17 AppKit 0x00007fff8b3b147f NSApplicationMain + 398
18 KvcFun 0x0000000100001132 main + 34
19 KvcFun 0x0000000100001104 start + 52
20 ??? 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminate called throwing an exception
(lldb)

I have checked my code and settings against the answers for this chapter on this website and I can’t see any differences. Could Mountain Lion 10.8 and XCode 4.4 be causing me problems.

Any help would be appreciated.

Thank You

Marc


#5

Marc,

Check the Connections panels in your XIB file to see what’s bound to the App Delegate. You can do this by right or control-clicking on the App Delegate in the Objects list on the left. Toward the bottom you should see a list of what is bound to the App Delegate. One of those is expecting to find a bool, so I would expect that you are missing the model key path, or have accidentally bound something you didn’t intend to, which can happen.

Adam


#6

I had the same problem happen. I had the slider bound to “Kvc Fun App Delegate” and the model key method set to “self.fido”. The program crashed on the first run and ran fine on the second try. Weird.