I want to store the FTP Password in a Keychain rather than in the NSUserDefaults. So I used a wrapper called EMKeyChain to store the problem. The problem being is that it won't load the password when the Preference Window is loaded:
Note: FTPPassword is a IBOutlet for NSTextField in PreferenceController.h
-(void)windowDidLoad
{
//Check Login Keychain
[self loadlogin];
//Set FTP Password Delegate to PreferenceController
[FTPPassword setDelegate:self];
//Load Password
EMGenericKeychainItem *keychainItem = [EMGenericKeychainItem genericKeychainItemForService:#"MelScrobbleX" withUsername: #"ftp"];
if (keychainItem.password != nil) {
[FTPPassword setValue:keychainItem.password];
}
Resulting in this big nasty error:
2010-09-05 19:31:51.360 MelScrobbleX[83291:a0f] -[NSSecureTextField setValue:]: unrecognized selector sent to instance 0x10c4be0
2010-09-05 19:31:51.363 MelScrobbleX[83291:a0f] HIToolbox: ignoring exception '-[NSSecureTextField setValue:]: unrecognized selector sent to instance 0x10c4be0' that raised inside Carbon event dispatch
(
0 CoreFoundation 0x977d6bba __raiseError + 410
1 libobjc.A.dylib 0x9022f509 objc_exception_throw + 56
2 CoreFoundation 0x978238db -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x9777d7e6 ___forwarding___ + 950
4 CoreFoundation 0x9777d3b2 _CF_forwarding_prep_0 + 50
5 MelScrobbleX 0x000193f2 -[PreferenceController windowDidLoad] + 157
6 AppKit 0x96d7941f -[NSWindowController _windowDidLoad] + 525
7 AppKit 0x96d072b0 -[NSWindowController window] + 123
8 AppKit 0x96f6c0f8 -[NSWindowController showWindow:] + 36
9 AppKit 0x96d61f1e -[NSApplication sendAction:to:from:] + 112
10 AppKit 0x96d61dd1 -[NSMenuItem _corePerformAction] + 435
11 AppKit 0x96d61ac2 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 174
12 AppKit 0x96d619ae -[NSMenu performActionForItemAtIndex:] + 65
13 AppKit 0x96d61961 -[NSMenu _internalPerformActionForItemAtIndex:] + 50
14 AppKit 0x96d618c7 -[NSMenuItem _internalPerformActionThroughMenuIfPossible] + 97
15 AppKit 0x96d6180b -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 336
16 AppKit 0x96d55f49 NSSLMMenuEventHandler + 404
17 HIToolbox 0x9370df2f _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1567
18 HIToolbox 0x9370d1f6 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 411
19 HIToolbox 0x9372f9bb SendEventToEventTarget + 52
20 HIToolbox 0x9375bfa7 _ZL18SendHICommandEventmPK9HICommandmmhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 448
21 HIToolbox 0x93780d1c SendMenuCommandWithContextAndModifiers + 66
22 HIToolbox 0x93780cd1 SendMenuItemSelectedEvent + 121
23 HIToolbox 0x93780bda _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 152
24 HIToolbox 0x93902342 _ZL19PopUpMenuSelectCoreP8MenuData5PointdS1_tjPK4RecttmS4_S4_PK10__CFStringPP13OpaqueMenuRefPt + 1851
25 HIToolbox 0x93902699 _HandlePopUpMenuSelection7 + 678
26 AppKit 0x96febe97 _NSSLMPopUpCarbonMenu3 + 3938
27 AppKit 0x97275bdb +[NSStatusBarButtonCell popupStatusBarMenu:inRect:ofView:withEvent:] + 962
28 AppKit 0x97275241 -[NSStatusBarButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 151
29 AppKit 0x96e3ae93 -[NSControl mouseDown:] + 812
30 AppKit 0x96e38e9c -[NSWindow sendEvent:] + 5549
31 AppKit 0x972761f8 -[NSStatusBarWindow sendEvent:] + 82
32 AppKit 0x96d51aff -[NSApplication sendEvent:] + 6431
33 AppKit 0x96ce55bb -[NSApplication run] + 917
34 AppKit 0x96cdd5ed NSApplicationMain + 574
35 MelScrobbleX 0x00002eda start + 54
)
The program creates a new keychain item every time the password changes even though the keychain item exists already. (This selector is for FTPPassword)
- (void)controlTextDidEndEditing:(NSNotification *)aNotification {
EMGenericKeychainItem *keychainItem = [EMGenericKeychainItem genericKeychainItemForService:#"MelScrobbleX" withUsername: #"ftp"];
if (keychainItem.password == nil) {
//Create Keychain
NSLog(#"Creating Keychain");
[EMGenericKeychainItem addGenericKeychainItemForService:#"MelScrobbleX" withUsername:#"ftp" password:[FTPPassword stringValue]];
}
else if (keychainItem.password != [FTPPassword stringValue]){
//Save Password
NSLog(#"Saving Password");
keychainItem.password = [FTPPassword stringValue];
}
else if ([[FTPPassword stringValue] length] == 0){
//Blank Password. Remove Keychain Item
NSLog(#"Deleting Password");
[keychainItem removeFromKeychain];
}
}
Notes: The required frameworks are already linked (Security.framework and Carbon.framework) and this error happens with GC on and off. Also, I'm using the Mac OS X 10.5 SDK.
Your error says
-[NSSecureTextField setValue:]: unrecognized selector sent to instance 0x10c4be0
You should look up the reference, see NSSecureTextField. By traversing the class hierarchy, you eventually find there's no such method as setValue:.
I guess you wanted to do
[FTPPassword setStringValue:keychainItem.password];
instead of
[FTPPassword setValue:keychainItem.password];
I would've thought that the compiler should have warned against using setValue: because there's no such method in NSControl,
but I found this informal protocol defining setValue: as a category method of NSObject. Alas...
Related
I'm trying to write a piece of code that would "modernize" a video file. This is the code :
NSOpenPanel *openPanel = [[NSOpenPanel alloc] init];
[openPanel setCanChooseFiles:NO];
[openPanel setCanChooseDirectories:YES];
if([openPanel runModal] == NSCancelButton)
return;
NSMutableString *destination = [[[openPanel URL] absoluteString] mutableCopy];
[destination appendString:#"/"];
[destination appendString:[self fileName:[url absoluteString] withExtention:NO]];
[destination appendString:#".m4v"];
QTMovieModernizer *modernizer = [[QTMovieModernizer alloc] initWithSourceURL:url destinationURL:[NSURL URLWithString:destination]];
[modernizer modernizeWithCompletionHandler:^{NSLog(#"Modernization complete to file %# - error : %#",[modernizer destinationURL],[modernizer error]);}];
The problem is that I get an NSInvalidArgumentException. I've checked the source and destination url carefully and they seem to be ok. The error seems to happen at the initialization the QTMovieModernizer instance. What can be going wrong here?
Error details :
NSInvalidArgumentException
(
0 CoreFoundation 0x00007fff82cdc25c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff84c8ae75 objc_exception_throw + 43
2 QTKit 0x00007fff84fc4303 -[QTMovieModernizer createUniqueLegacyFilePath:extension:inDirectory:] + 0
3 MediaPlayer 0x0000000100003bb9 -[AppDelegate modernize:] + 1097
4 MediaPlayer 0x000000010000536f -[AppDelegate openFile:] + 879
5 AppKit 0x00007fff8339d340 -[NSApplication sendAction:to:from:] + 327
6 AppKit 0x00007fff833b82a8 -[NSMenuItem _corePerformAction] + 394
7 AppKit 0x00007fff833b7fe4 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 117
8 AppKit 0x00007fff8340748d -[NSMenu _internalPerformActionForItemAtIndex:] + 35
9 AppKit 0x00007fff83407309 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 104
10 AppKit 0x00007fff833ae0d6 NSSLMMenuEventHandler + 716
11 HIToolbox 0x00007fff8b7d21d4 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 892
12 HIToolbox 0x00007fff8b7d1787 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 385
13 HIToolbox 0x00007fff8b7e5880 SendEventToEventTarget + 40
14 HIToolbox 0x00007fff8b81b640 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 420
15 HIToolbox 0x00007fff8b84e238 SendMenuCommandWithContextAndModifiers + 59
16 HIToolbox 0x00007fff8b84e1e0 SendMenuItemSelectedEvent + 178
17 HIToolbox 0x00007fff8b84e0bf _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 94
18 HIToolbox 0x00007fff8b856095 _ZL14MenuSelectCoreP8MenuData5PointdjPP13OpaqueMenuRefPt + 718
19 HIToolbox 0x00007fff8b855cc1 _HandleMenuSelection2 + 446
20 AppKit 0x00007fff8332073c _NSHandleCarbonMenuEvent + 284
21 AppKit 0x00007fff8317f6be _DPSNextEvent + 2170
22 AppKit 0x00007fff8317ea2b -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
23 AppKit 0x00007fff83172b2c -[NSApplication run] + 553
24 AppKit 0x00007fff8315d913 NSApplicationMain + 940
25 MediaPlayer 0x0000000100008362 main + 34
26 libdyld.dylib 0x00007fff830d95fd start + 1
27 ??? 0x0000000000000003 0x0 + 3
)
EDIT :
I found out that -fileName:withExtension: returns a string by replacing %20 by spaces. After handling this, the exception at the initsilizing is gone but instead, I have the following error when converting the file :
<<<< QTMovieModernizer >>>> FigFormatUtilsCreateFormatReader: Error -12848 from FigFormatReaderCreateForStream
<<<< QTMovieModernizer >>>> formatReaderForSourceURL: Error in FormatReaderForSourceURL: -12848
I have the following code to retrieve the currentTrack's artwork (using iTunes.h):
iTunesArtwork *iTunesArtwork = [[iTunes.currentTrack artworks] objectAtIndex:0];
NSImage *artwork = iTunesArtwork.data;
if (artwork != nil){
[_musicImageView setImage:artwork];
}
It works for most of the tracks but sometimes it gives me this error (even when the track has an image):
NSImageCell's object value must be an NSImage.
2012-12-28 00:22:12.217 App[3256:303] (
0 CoreFoundation 0x00007fff904360a6 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8d5bf3f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff90435e7c +[NSException raise:format:] + 204
3 AppKit 0x00007fff9747c31b -[NSImageCell setObjectValue:] + 106
4 AppKit 0x00007fff974b8563 -[NSImageView setImage:] + 90
5 App 0x0000000100001b38 -[AppDelegate setupPlayer] + 600
6 Foundation 0x00007fff8d10c513 __NSFireTimer + 96
7 CoreFoundation 0x00007fff903f2da4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
8 CoreFoundation 0x00007fff903f28bd __CFRunLoopDoTimer + 557
9 CoreFoundation 0x00007fff903d8099 __CFRunLoopRun + 1513
10 CoreFoundation 0x00007fff903d76b2 CFRunLoopRunSpecific + 290
11 HIToolbox 0x00007fff939e40a4 RunCurrentEventLoopInMode + 209
12 HIToolbox 0x00007fff939e3e42 ReceiveNextEventCommon + 356
13 HIToolbox 0x00007fff939e3cd3 BlockUntilNextEventMatchingListInMode + 62
14 AppKit 0x00007fff97337613 _DPSNextEvent + 685
15 AppKit 0x00007fff97336ed2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
16 AppKit 0x00007fff9732e283 -[NSApplication run] + 517
17 AppKit 0x00007fff972d2cb6 NSApplicationMain + 869
18 App 0x0000000100001822 main + 34
19 libdyld.dylib 0x00007fff93cb77e1 start + 0
)
Any ideas on what's going on?
make sure it is an image -- not just check if its not nil, thats not enough. the type in an h file must not be the type the object really has. It is more like... it SHOULD be an image :D
if([artwork isKindOfClass:[NSImage class]]) {
....
from the comments.
That didnt always work. ell. no more crashes but some images didnt show. we used the rawData as fallback:
//kind of like this
if(![artwork isKindOfClass:[NSImage class]]) {
artwork = [[NSImage alloc] initWithData:tunesArtwork.rawData];
}
if([artwork isKindOfClass:[NSImage class]]) {
...
}
Here is my code:
.h
NSMutableString *buffer, *tmpBuffer;
int status; // 0=waiting for <DMX>, 1=recording
.m
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
buffer = [[NSMutableString alloc] init];
tmpBuffer = [[NSMutableString alloc] init];
status = 0;
}
- (void) receivedData:(NSString *)data {
// status=0 means we are still looking for start tag
if(status == 0) {
// add new data to last examined chunk (if any)
[tmpBuffer appendString:data];
// try to locate the open tag inside the tmpBuffer
NSRange range = [tmpBuffer rangeOfString:#"<DMX>" options:NSCaseInsensitiveSearch];
// if found, store the portion after the start tag into buffer
if(range.location != NSNotFound) {
range.length = [tmpBuffer length] - range.location + 5; // 5 is length of start tag...
[buffer setString:[tmpBuffer substringWithRange:range]];
status = 1; // set status to 1 so we know recording started
} else {
// store last examined chunk
[tmpBuffer setString:data];
}
} else {
[buffer appendString:data];
NSRange range = [buffer rangeOfString:#"</DMX>" options:NSCaseInsensitiveSearch];
if(range.location != NSNotFound) {
range.length = [buffer length] - range.location;
[self fullDMXReceived:buffer];
[buffer deleteCharactersInRange:range];
status = 0;
}
}
}
- (void) fullDMXReceived:(NSString*)finalData {
NSRunAlertPanel(#"", finalData, #"", #"", #"");
}
Here is the error:
2012-12-02 14:39:00.356 Chatty Mac[1805:303] *** Assertion failure in -[NSTextFieldCell _objectValue:forString:errorDescription:], /SourceCache/AppKit/AppKit-1187.34/AppKit.subproj/NSCell.m:1532
2012-12-02 14:39:00.362 Chatty Mac[1805:303] An uncaught exception was raised
2012-12-02 14:39:00.367 Chatty Mac[1805:303] Invalid parameter not satisfying: aString != nil
2012-12-02 14:39:00.374 Chatty Mac[1805:303] (
0 CoreFoundation 0x00007fff93e350a6 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8f52e3f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff93e34ee8 +[NSException raise:format:arguments:] + 104
3 Foundation 0x00007fff933fe6a2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
4 AppKit 0x00007fff92660205 -[NSCell _objectValue:forString:errorDescription:] + 159
5 AppKit 0x00007fff9266015f -[NSCell _objectValue:forString:] + 20
6 AppKit 0x00007fff926600db -[NSCell setStringValue:] + 39
7 AppKit 0x00007fff926f43fc -[NSControl setStringValue:] + 138
8 AppKit 0x00007fff928c2ba8 -[NSAlert buildAlertStyle:title:formattedMsg:first:second:third:oldStyle:] + 7479
9 AppKit 0x00007fff928c478b _NXDoLocalRunAlertPanel + 343
10 AppKit 0x00007fff928c461c NSRunAlertPanel + 157
11 Chatty Mac 0x00000001000070bd -[AppDelegate fullDMXReceived:] + 61
12 Chatty Mac 0x0000000100007036 -[AppDelegate receivedData:] + 582
13 Chatty Mac 0x000000010000e751 -[ORSSerialPortDemoController serialPort:didReceiveData:] + 401
14 Chatty Mac 0x000000010000a6fa -[ORSSerialPort receiveData:] + 170
15 Chatty Mac 0x0000000100009676 __block_global_1 + 38
16 libdispatch.dylib 0x00007fff9637bf01 _dispatch_call_block_and_release + 15
17 libdispatch.dylib 0x00007fff963780b6 _dispatch_client_callout + 8
18 libdispatch.dylib 0x00007fff9637d0c8 _dispatch_main_queue_callback_4CF + 275
19 CoreFoundation 0x00007fff93dd70fe __CFRunLoopRun + 1614
20 CoreFoundation 0x00007fff93dd66b2 CFRunLoopRunSpecific + 290
21 HIToolbox 0x00007fff949130a4 RunCurrentEventLoopInMode + 209
22 HIToolbox 0x00007fff94912e42 ReceiveNextEventCommon + 356
23 HIToolbox 0x00007fff94912cd3 BlockUntilNextEventMatchingListInMode + 62
24 AppKit 0x00007fff92682613 _DPSNextEvent + 685
25 AppKit 0x00007fff92681ed2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
26 AppKit 0x00007fff92679283 -[NSApplication run] + 517
27 AppKit 0x00007fff9261dcb6 NSApplicationMain + 869
28 Chatty Mac 0x00000001000056d2 main + 34
29 Chatty Mac 0x0000000100001da4 start + 52
30 ??? 0x0000000000000003 0x0 + 3
)
2012-12-02 14:39:00.475 Chatty Mac[1805:303] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: aString != nil'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff93e350a6 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8f52e3f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff93e34ee8 +[NSException raise:format:arguments:] + 104
3 Foundation 0x00007fff933fe6a2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
4 AppKit 0x00007fff92660205 -[NSCell _objectValue:forString:errorDescription:] + 159
5 AppKit 0x00007fff9266015f -[NSCell _objectValue:forString:] + 20
6 AppKit 0x00007fff926600db -[NSCell setStringValue:] + 39
7 AppKit 0x00007fff926f43fc -[NSControl setStringValue:] + 138
8 AppKit 0x00007fff928c2ba8 -[NSAlert buildAlertStyle:title:formattedMsg:first:second:third:oldStyle:] + 7479
9 AppKit 0x00007fff928c478b _NXDoLocalRunAlertPanel + 343
10 AppKit 0x00007fff928c461c NSRunAlertPanel + 157
11 Chatty Mac 0x00000001000070bd -[AppDelegate fullDMXReceived:] + 61
12 Chatty Mac 0x0000000100007036 -[AppDelegate receivedData:] + 582
13 Chatty Mac 0x000000010000e751 -[ORSSerialPortDemoController serialPort:didReceiveData:] + 401
14 Chatty Mac 0x000000010000a6fa -[ORSSerialPort receiveData:] + 170
15 Chatty Mac 0x0000000100009676 __block_global_1 + 38
16 libdispatch.dylib 0x00007fff9637bf01 _dispatch_call_block_and_release + 15
17 libdispatch.dylib 0x00007fff963780b6 _dispatch_client_callout + 8
18 libdispatch.dylib 0x00007fff9637d0c8 _dispatch_main_queue_callback_4CF + 275
19 CoreFoundation 0x00007fff93dd70fe __CFRunLoopRun + 1614
20 CoreFoundation 0x00007fff93dd66b2 CFRunLoopRunSpecific + 290
21 HIToolbox 0x00007fff949130a4 RunCurrentEventLoopInMode + 209
22 HIToolbox 0x00007fff94912e42 ReceiveNextEventCommon + 356
23 HIToolbox 0x00007fff94912cd3 BlockUntilNextEventMatchingListInMode + 62
24 AppKit 0x00007fff92682613 _DPSNextEvent + 685
25 AppKit 0x00007fff92681ed2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
26 AppKit 0x00007fff92679283 -[NSApplication run] + 517
27 AppKit 0x00007fff9261dcb6 NSApplicationMain + 869
28 Chatty Mac 0x00000001000056d2 main + 34
29 Chatty Mac 0x0000000100001da4 start + 52
30 ??? 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminate called throwing an exception
(lldb)
It's happening where [self fullDMXReceived:buffer]; is called because when I remove it, it doesn't crash.
What's happening here? Can anyone decode this error?
FYI, I'm calling receivedData from another class like this: AppDelegate *theAppDelegate = [[AppDelegate alloc] init]; [theAppDelegate receivedData:string]; Could this be a problem?
When I run AppDelegate *theAppDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
I get this error message:
2012-12-03 06:00:12.791 Chatty Mac[1580:303] An uncaught exception was raised
2012-12-03 06:00:12.793 Chatty Mac[1580:303] -[__NSCFString substringWithRange:]: Range or index out of bounds
2012-12-03 06:00:12.797 Chatty Mac[1580:303] (
0 CoreFoundation 0x00007fff8d0ee0a6 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff887e73f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8d0ede7c +[NSException raise:format:] + 204
3 CoreFoundation 0x00007fff8d0c555d -[__NSCFString substringWithRange:] + 109
4 Chatty Mac 0x0000000100006ecb -[AppDelegate receivedData:] + 283
5 Chatty Mac 0x000000010000e772 -[ORSSerialPortDemoController serialPort:didReceiveData:] + 466
6 Chatty Mac 0x000000010000a6ba -[ORSSerialPort receiveData:] + 170
7 Chatty Mac 0x0000000100009636 __block_global_1 + 38
8 libdispatch.dylib 0x00007fff8f634f01 _dispatch_call_block_and_release + 15
9 libdispatch.dylib 0x00007fff8f6310b6 _dispatch_client_callout + 8
10 libdispatch.dylib 0x00007fff8f6360c8 _dispatch_main_queue_callback_4CF + 275
11 CoreFoundation 0x00007fff8d0900fe __CFRunLoopRun + 1614
12 CoreFoundation 0x00007fff8d08f6b2 CFRunLoopRunSpecific + 290
13 HIToolbox 0x00007fff8dbcc0a4 RunCurrentEventLoopInMode + 209
14 HIToolbox 0x00007fff8dbcbe42 ReceiveNextEventCommon + 356
15 HIToolbox 0x00007fff8dbcbcd3 BlockUntilNextEventMatchingListInMode + 62
16 AppKit 0x00007fff8b93b613 _DPSNextEvent + 685
17 AppKit 0x00007fff8b93aed2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
18 AppKit 0x00007fff8b932283 -[NSApplication run] + 517
19 AppKit 0x00007fff8b8d6cb6 NSApplicationMain + 869
20 Chatty Mac 0x0000000100005692 main + 34
21 Chatty Mac 0x0000000100001d64 start + 52
22 ??? 0x0000000000000003 0x0 + 3
)
2012-12-03 06:00:12.799 Chatty Mac[1580:303] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFString substringWithRange:]: Range or index out of bounds'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff8d0ee0a6 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff887e73f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8d0ede7c +[NSException raise:format:] + 204
3 CoreFoundation 0x00007fff8d0c555d -[__NSCFString substringWithRange:] + 109
4 Chatty Mac 0x0000000100006ecb -[AppDelegate receivedData:] + 283
5 Chatty Mac 0x000000010000e772 -[ORSSerialPortDemoController serialPort:didReceiveData:] + 466
6 Chatty Mac 0x000000010000a6ba -[ORSSerialPort receiveData:] + 170
7 Chatty Mac 0x0000000100009636 __block_global_1 + 38
8 libdispatch.dylib 0x00007fff8f634f01 _dispatch_call_block_and_release + 15
9 libdispatch.dylib 0x00007fff8f6310b6 _dispatch_client_callout + 8
10 libdispatch.dylib 0x00007fff8f6360c8 _dispatch_main_queue_callback_4CF + 275
11 CoreFoundation 0x00007fff8d0900fe __CFRunLoopRun + 1614
12 CoreFoundation 0x00007fff8d08f6b2 CFRunLoopRunSpecific + 290
13 HIToolbox 0x00007fff8dbcc0a4 RunCurrentEventLoopInMode + 209
14 HIToolbox 0x00007fff8dbcbe42 ReceiveNextEventCommon + 356
15 HIToolbox 0x00007fff8dbcbcd3 BlockUntilNextEventMatchingListInMode + 62
16 AppKit 0x00007fff8b93b613 _DPSNextEvent + 685
17 AppKit 0x00007fff8b93aed2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
18 AppKit 0x00007fff8b932283 -[NSApplication run] + 517
19 AppKit 0x00007fff8b8d6cb6 NSApplicationMain + 869
20 Chatty Mac 0x0000000100005692 main + 34
21 Chatty Mac 0x0000000100001d64 start + 52
22 ??? 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminate called throwing an exception
(lldb)
In comments, you say:
AppDelegate *theAppDelegate = [[AppDelegate alloc] init];
[theAppDelegate receivedData:string];
That creates a new AppDelegate object, which means the applicationDidFinishLaunching method isn't being called (it was already called in the first AppDelegate instance). Use the original one instead.
AppDelegate *theAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
Working through the book Cocoa Programming for Mac OS X (third edition) from Aaron Hillegass I am now at Chapter 9, at the end of section Adding Undo to RaiseMan. Hillegass tells you to add two methods to your class MyDocument and then build the app to see that undo/redo is added and working.
But, it isn't working (why else would I be here?). It says:
2012-11-27 19:55:16.231 RaiseMan[293:a0f] HIToolbox: ignoring exception 'undo: NSUndoManager 0x100188a30 is in invalid state, undo was called with too many nested undo groups' that raised inside Carbon event dispatch
(
0 CoreFoundation 0x00007fff88c26784 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00007fff858ddf03 objc_exception_throw + 45
2 CoreFoundation 0x00007fff88c265a7 +[NSException raise:format:arguments:] + 103
3 CoreFoundation 0x00007fff88c26534 +[NSException raise:format:] + 148
4 Foundation 0x00007fff86fd0e17 -[NSUndoManager undo] + 239
5 AppKit 0x00007fff8976eeda -[NSApplication sendAction:to:from:] + 95
6 AppKit 0x00007fff8979346a -[NSMenuItem _corePerformAction] + 365
7 AppKit 0x00007fff897931d4 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 121
8 AppKit 0x00007fff89a18cf4 -[NSMenu _internalPerformActionForItemAtIndex:] + 35
9 AppKit 0x00007fff898ca9e9 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 136
10 AppKit 0x00007fff8977599c NSSLMMenuEventHandler + 321
11 HIToolbox 0x00007fff83d937f7 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1002
12 HIToolbox 0x00007fff83d92d46 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 395
13 HIToolbox 0x00007fff83db0a81 SendEventToEventTarget + 45
14 HIToolbox 0x00007fff83ddfc35 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 387
15 HIToolbox 0x00007fff83e0ca0a SendMenuCommandWithContextAndModifiers + 56
16 HIToolbox 0x00007fff83e0c9c2 SendMenuItemSelectedEvent + 101
17 HIToolbox 0x00007fff83e0c8d2 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 150
18 HIToolbox 0x00007fff83dedc27 _ZL14MenuSelectCoreP8MenuData5PointdjPP13OpaqueMenuRefPt + 467
19 HIToolbox 0x00007fff83ded37c _HandleMenuSelection2 + 453
20 AppKit 0x00007fff89646851 _NSHandleCarbonMenuEvent + 236
21 AppKit 0x00007fff8961a362 _DPSNextEvent + 1908
22 AppKit 0x00007fff89619801 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155
23 AppKit 0x00007fff895df68f -[NSApplication run] + 395
24 AppKit 0x00007fff895d83b0 NSApplicationMain + 364
25 RaiseMan 0x000000010000160a main + 33
26 RaiseMan 0x0000000100001218 start + 52
27 ??? 0x0000000000000001 0x0 + 1
)
in the console when I click undo or press cmd+z.
I found solutions for this online, but they are all about 'UndoGroups' or something similar.
I know that the exception is about nested undo groups, but I don't use them (AFAIK), I don't even know what they are.
I don't know what else information I should give, so please ask in the comments for code fragments etc.
For future readers:
Hillegass tells you to add 2 methods: -insertObject:inEmployeesAtIndex: and -removeObjectFromEmployeesAtIndex:. In the second method you have to do:
NSUndoManager *undo = [self undoManager];
[[undo prepareWithInvocationTarget:self] insertObject:p inEmployeesAtIndex:index];
But I did:
NSUndoManager *undo = [self undoManager];
[[undo prepareWithInvocationTarget:self] insertObject:p atIndex:index]; //atIndex: instead of inEmployeesAtIndex:
In my subclass of NSWindowController, [self window] is null.
In my nib file THERE IS a link between the File's Owner (my subclass) and the Window View.
Why do I get this error ?
It stopped to work when I refactored the File Owner's class (the subclass of NSWindowController). I've updated it in the nib so I don't understand why it stopped to work.
Crashing line:
session = [NSApp beginModalSessionForWindow:[self window]];
2011-10-25 12:27:14.377 MyApp [13161:b0f] *** Assertion failure in -[CBApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:], /SourceCache/AppKit/AppKit-1138.23/AppKit.subproj/NSApplication.m:3861
2011-10-25 12:27:14.377 MyApp[13161:b0f] An uncaught exception was raised
2011-10-25 12:27:14.378 MyApp[13161:b0f] Modal session requires modal window
2011-10-25 12:27:14.380 MyApp[13161:b0f] (
0 CoreFoundation 0x92e01d87 __raiseError + 231
1 libobjc.A.dylib 0x9317e149 objc_exception_throw + 155
2 CoreFoundation 0x92d69619 +[NSException raise:format:arguments:] + 137
3 Foundation 0x9c41c36f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 AppKit 0x958a987d -[NSApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:] + 725
5 AppKit 0x958a1973 -[NSApplication beginModalSessionForWindow:] + 72
6 MyApp 0x00042ca3 -[CBWindowController showModal:] + 131
7 MyApp 0x00023c46 -[CBDocument showLinkWindow:shouldLinkAndUpdate:selectedOnly:] + 1174
8 MyApp 0x00023cb1 -[CBDocument linkAllRootItems:] + 81
9 MyApp 0x0002a9b4 -[CBApplicationDelegate linkAllItems:] + 100
10 CoreFoundation 0x92d57091 -[NSObject performSelector:withObject:] + 65
11 AppKit 0x956e1cb3 -[NSApplication sendAction:to:from:] + 232
12 AppKit 0x957d5caf -[NSMenuItem _corePerformAction] + 536
13 AppKit 0x957d592c -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 171
14 AppKit 0x957d4fb5 -[NSMenu _performActionWithHighlightingForItemAtIndex:sendAccessibilityNotification:] + 79
15 AppKit 0x95aaddab -[NSMenu performActionForItemAtIndex:] + 65
16 AppKit 0x95aaddde -[NSMenu _internalPerformActionForItemAtIndex:] + 45
17 AppKit 0x95ab200f -[NSMenuItem _internalPerformActionThroughMenuIfPossible] + 106
18 AppKit 0x9591ba10 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 172
19 AppKit 0x9574a916 NSSLMMenuEventHandler + 452
20 HIToolbox 0x9b175920 _Z22_InvokeEventHandlerUPPP25OpaqueEventHandlerCallRefP14OpaqueEventRefPvPFlS0_S2_S3_E + 36
21 HIToolbox 0x9aff1803 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1602
22 HIToolbox 0x9aff0c80 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 482
23 HIToolbox 0x9b005aa9 SendEventToEventTarget + 76
24 HIToolbox 0x9b175de4 _ZL18SendHICommandEventmPK9HICommandmmhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 482
25 HIToolbox 0x9b175e4e SendMenuCommandWithContextAndModifiers + 70
26 HIToolbox 0x9b1e0697 SendMenuItemSelectedEvent + 275
27 HIToolbox 0x9b0423f9 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 129
28 HIToolbox 0x9b1d1574 _ZL14MenuSelectCoreP8MenuData5PointdmPP13OpaqueMenuRefPt + 608
29 HIToolbox 0x9b03a0b2 _HandleMenuSelection2 + 636
30 HIToolbox 0x9b039e31 _HandleMenuSelection + 53
31 AppKit 0x95646356 _NSHandleCarbonMenuEvent + 302
32 AppKit 0x955d662e _DPSNextEvent + 2196
33 AppKit 0x955d58ab -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 113
34 AppKit 0x955d1c22 -[NSApplication run] + 911
35 AppKit 0x9586618a NSApplicationMain + 1054
36 MyApp 0x000042f4 main + 36
37 MyApp 0x00002e06 start + 54
How the NSWindowController is created:
CBWindowController *windowController = [[subClass alloc] init];
[windowController setRanAsModal:YES];
[windowController setDelegate:self];
[windowController setRootDocument:[NSApp mainWindowDocument]];
[windowController loadWindow];
[windowController centerOnMainWindow:sender];
[self window] must point to a valid window object. From your comments, it is not.
You must check and re-connect the window outlet, or, if there is no such outlet, ensure that a valid object is held in that variable.
Automatic refactoring doesn't appear to catch everything - so a search of your project for the old name would seem to be a worthwhile exercise after refactoring to prevent issues like this in the future.
I'm willing to bet you are initializing it wrong. You need to specifiy the NIB name when you initialize your class, like so:
CBWindowController *windowController =
[[subClass alloc] initWithWindowNibName:#"MyWindow" owner:nil];
Better yet, just fold that code into your window controller's init method.
Edit: Also, do NOT call loadWindow on your object, that method is called automatically when the window is accessed, as mentioned in the documentation.