QTMovieModernizer errors - objective-c

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

Related

NSOpenPanel error: NSConcreteMutableAttributedString initWithString:: nil value

I get this error when choosing a file in NSOpenPanel.
Im am using xCode 6.1.1 and Yosemite.
2015-02-19 21:21:11.396 Sagssystem[2239:56373] NSConcreteMutableAttributedString initWithString:: nil value
2015-02-19 21:21:11.399 Sagssystem[2239:56373] (
0 CoreFoundation 0x00007fff8bb9450c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8edb976e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8bb943bd +[NSException raise:format:] + 205
3 Foundation 0x00007fff860ba5a7 -[NSConcreteMutableAttributedString initWithString:] + 129
4 FinderKit 0x00007fff8d345e88 -[FI_TColumnPreviewPropertyTaggingTokenFieldController viewLoaded] + 183
5 FinderKit 0x00007fff8d21a371 -[FI_TViewController awakeFromNib] + 106
6 CoreFoundation 0x00007fff8baa259f -[NSSet makeObjectsPerformSelector:] + 223
7 AppKit 0x00007fff89e4d90d -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1216
8 AppKit 0x00007fff8a02a342 -[NSNib _instantiateNibWithExternalNameTable:options:] + 677
9 AppKit 0x00007fff8a029f92 -[NSNib _instantiateWithOwner:options:topLevelObjects:] + 143
10 AppKit 0x00007fff8a029287 -[NSViewController loadView] + 272
11 FinderKit 0x00007fff8d21a41a -[FI_TViewController loadView] + 98
12 AppKit 0x00007fff89fa85e7 -[NSViewController _loadViewIfRequired] + 75
13 AppKit 0x00007fff89fa8551 -[NSViewController view] + 30
14 FinderKit 0x00007fff8d347a5e -[FI_TColumnPreviewController initCommon] + 61
15 FinderKit 0x00007fff8d21a2a7 -[FI_TViewController initWithNibName:bundle:] + 59
16 FinderKit 0x00007fff8d2d2c3e -[FI_TColumnViewController browser:previewViewControllerForLeafItem:] + 288
17 AppKit 0x00007fff8a2da31c -[NSBrowser _hasLeafViewControllerForItem:] + 156
18 AppKit 0x00007fff8a2c8fbf -[NSBrowser _isExpandableItem:] + 51
19 AppKit 0x00007fff8a2d1bb1 -[NSBrowser _doClickAndQueueSendingOfAction:] + 277
20 AppKit 0x00007fff8a2d13ff -[NSBrowser doClick:] + 384
21 FinderKit 0x00007fff8d2c921f -[FI_TColumnView doClick:] + 142
22 libsystem_trace.dylib 0x00007fff8d69fcd7 _os_activity_initiate + 75
23 AppKit 0x00007fff8a078671 -[NSApplication sendAction:to:from:] + 452
24 AppKit 0x00007fff8a08e006 -[NSControl sendAction:to:] + 86
25 AppKit 0x00007fff8a13e173 -[NSTableView _sendAction:to:row:column:] + 90
26 AppKit 0x00007fff8a13caa6 -[NSTableView mouseDown:] + 6506
27 AppKit 0x00007fff8a2e1216 -[NSBrowserTableView mouseDown:] + 195
28 FinderKit 0x00007fff8d2c355e -[FI_TBrowserTableView mouseDown:] + 693
29 AppKit 0x00007fff8a5ddcf0 -[NSWindow _reallySendEvent:isDelayedEvent:] + 13331
30 AppKit 0x00007fff89f83b14 -[NSWindow sendEvent:] + 468
31 AppKit 0x00007fff89f807f1 -[NSApplication sendEvent:] + 4183
32 AppKit 0x00007fff89ea9e08 -[NSApplication run] + 711
33 AppKit 0x00007fff89e24e64 NSApplicationMain + 1832
34 Sagssystem 0x0000000100045e62 main + 34
35 libdyld.dylib 0x00007fff8380a5c9 start + 1
)
I call NSOpenPanel with this code:
NSOpenPanel *panel = [NSOpenPanel openPanel];
NSArray * fileTypes = [NSArray arrayWithObjects:#"png",#"jpg",#"jpeg",#"gif",#"pdf",nil];
[panel setAllowedFileTypes:fileTypes];
[panel setCanChooseFiles:YES];
[panel setCanChooseDirectories:NO];
[panel setAllowsMultipleSelection:YES]; // yes if more than one dir is allowed
[panel beginSheetModalForWindow:self.view.window completionHandler: ^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton) {
for (NSURL *fileURL in [panel URLs]) {
}
return;
} else {
[self dismissController:self];
}
}];
The error appears first when I choose a file.
The app does not crash and I do get the filenames.
Hope someone can help :)

Yosemite: NSSavePanel: __NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array

After upgrading to Yosemite, I'm getting a very weird crash when I run a NSSavePanel in my app. For example, I select openDocument: and it crashes. Or I open the panel to browse files and it crashes.
An uncaught exception was raised
2014-10-24 09:51:28.429 MyApp[2240:374020] *** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array
2014-10-24 09:51:28.431 MyApp[2240:374020] (
0 CoreFoundation 0x97c59343 __raiseError + 195
1 libobjc.A.dylib 0x973bea2a objc_exception_throw + 276
2 CoreFoundation 0x97b1cf8c -[__NSArrayI objectAtIndex:] + 204
3 MyApp 0x0013c830 -[NSArray(CocoaDevUsersAdditions) firstObject] + 41
4 AppKit 0x94567f16 _NSAccessibilityEntryPointValueForAttribute + 2116
5 AppKit 0x9456829e NSAccessibilityEntryPointValueForAttribute + 24
6 AppKit 0x9435ff4c ValueOfAttributeWithDefault + 80
7 AppKit 0x94090fa2 NSAccessibilityChildren + 47
8 AppKit 0x94090f48 NSAccessibilityUnignoredChildrenForOnlyChild + 99
9 AppKit 0x94090e50 NSAccessibilityUnignoredDescendant + 42
10 AppKit 0x94213a51 -[NSNibAXRelationshipConnector establishConnection] + 130
11 AppKit 0x9453e342 -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1061
12 AppKit 0x93ffaad7 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 56
13 AppKit 0x945debdd -[NSNib _instantiateNibWithExternalNameTable:options:] + 735
14 AppKit 0x941a3f77 -[NSNib instantiateNibWithOwner:topLevelObjects:] + 277
15 AppKit 0x94651cee -[NSSavePanel(NSSavePanelLayout) _initContentView] + 189
16 AppKit 0x9463d317 -[NSSavePanel initWithContentRect:styleMask:backing:defer:] + 645
17 AppKit 0x9463c6db +[NSSavePanel _crunchyRawUnbonedPanel] + 216
18 AppKit 0x945e978a +[NSOpenPanel openPanel] + 33
19 AppKit 0x944b66fb -[NSDocumentController _setupOpenPanel] + 42
20 AppKit 0x944b6b62 -[NSDocumentController beginOpenPanelWithCompletionHandler:] + 96
21 AppKit 0x944b6630 -[NSDocumentController openDocument:] + 413
22 libobjc.A.dylib 0x973bc853 -[NSObject performSelector:withObject:] + 70
23 AppKit 0x94380328 __36-[NSApplication sendAction:to:from:]_block_invoke + 51
24 libsystem_trace.dylib 0x9096dc03 _os_activity_initiate + 89
25 AppKit 0x941f3a11 -[NSApplication sendAction:to:from:] + 548
26 AppKit 0x9420f9ed -[NSMenuItem _corePerformAction] + 479
27 AppKit 0x9420f6c9 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 162
28 AppKit 0x9420ed54 -[NSMenu _performActionWithHighlightingForItemAtIndex:sendAccessibilityNotification:] + 79
29 AppKit 0x94585872 __38-[NSMenu performActionForItemAtIndex:]_block_invoke + 52
30 libsystem_trace.dylib 0x9096dc03 _os_activity_initiate + 89
31 AppKit 0x94260736 -[NSMenu performActionForItemAtIndex:] + 141
32 AppKit 0x9426069e -[NSMenu _internalPerformActionForItemAtIndex:] + 45
33 AppKit 0x94260669 -[NSMenuItem _internalPerformActionThroughMenuIfPossible] + 106
34 AppKit 0x942604c1 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 120
35 AppKit 0x94204487 NSSLMMenuEventHandler + 679
36 HIToolbox 0x905a45d4 _Z22_InvokeEventHandlerUPPP25OpaqueEventHandlerCallRefP14OpaqueEventRefPvPFlS0_S2_S3_E + 36
37 HIToolbox 0x903ee501 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 2291
38 HIToolbox 0x903ed4dc _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 402
39 HIToolbox 0x90400d25 SendEventToEventTarget + 88
40 HIToolbox 0x905a4452 _ZL18SendHICommandEventmPK9HICommandmmhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 447
41 HIToolbox 0x904650cc SendMenuCommandWithContextAndModifiers + 72
42 HIToolbox 0x90465074 SendMenuItemSelectedEvent + 207
43 HIToolbox 0x90464f38 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 145
44 HIToolbox 0x905fb902 _ZL14MenuSelectCoreP8MenuData5PointdmPP13OpaqueMenuRefPt + 775
45 HIToolbox 0x9046c266 _HandleMenuSelection2 + 512
46 HIToolbox 0x9046c050 _HandleMenuSelection + 55
47 AppKit 0x94182f3b _NSHandleCarbonMenuEvent + 359
48 AppKit 0x9400e321 _DPSNextEvent + 1702
49 AppKit 0x9400d7a1 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 186
50 AppKit 0x93ffff6c -[NSApplication run] + 907
51 AppKit 0x93fe94d0 NSApplicationMain + 2082
52 MyApp 0x00003215 start + 53
This is a bug with the extension class you are using. NSArray+CocoaDevUsersAdditions firstObject method is implemented wrong. The relevant parts of the crash log you posted are these three lines:
1 libobjc.A.dylib 0x973bea2a objc_exception_throw + 276
2 CoreFoundation 0x97b1cf8c -[__NSArrayI objectAtIndex:] + 204
3 MyApp 0x0013c830 -[NSArray(CocoaDevUsersAdditions) firstObject] + 41
The index 0 beyond bounds for empty array error happens when you try to access the index 0 of an array that contains no objects.
I found some code that I think matches the NSArray+CocoaDevUsersAdditions class at this URL
-(id)firstObject
{
return [self objectAtIndex:0];
}
The above code is wrong. It should check the count of objects first. Correct code should look like this:
-(id)firstObject
{
id result = nil;
if (self.count > 0) {
result = [self objectAtIndex:0];
}
return result;
}
So the problem is the NSArray extension you are using is implemented wrong.
Best solution: Remove your NSArray+CocoaDevUsersAdditions category and use the public firstObject method on NSArray

Thread 1 : signal SIGABRT - when trying to get NSMutableString

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];

self window is null but the Window outlet is correctly linked

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.

EMKeyChain Problems

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...