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];
Related
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
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
As we know the UITextView is more powerful in iOS 7, but here it performs more fragile. The following code works fine when inputting "rr" with Chinese input keyboard in iOS 6, but crashes in iOS 7.
- (void)viewDidLoad
{
[super viewDidLoad];
self.tv = [[UITextView alloc] initWithFrame:CGRectMake(0, 100, 320, 100)];
self.tv.backgroundColor = [UIColor yellowColor];
self.tv.textColor = [UIColor blackColor];
self.tv.editable = YES;
self.tv.delegate = self;
[self.view addSubview:self.tv];
}
-(void)textViewDidChange:(UITextView *)textView{
int maxLength = 2;
if (self.tv.text.length > maxLength) {
NSLog(#"self.tv.text :%#",self.tv.text);
NSLog(#"self.tv.text.length :%d",self.tv.text.length);
NSLog(#"maxLength :%d",maxLength);
self.tv.text = [self.tv.text substringToIndex:maxLength];
}
}
The log is as following:
2013-11-13 15:48:16.003 Test2[1388:70b] self.tv.text :r r
2013-11-13 15:48:16.004 Test2[1388:70b] self.tv.text.length :3
2013-11-13 15:48:16.005 Test2[1388:70b] maxLength :2
2013-11-13 15:48:16.032 Test2[1388:70b] *** Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray replaceObjectsInRange:withObject:length:: Out of bounds'
*** First throw call stack:
(
0 CoreFoundation 0x017355e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014b88b6 objc_exception_throw + 44
2 CoreFoundation 0x017353bb +[NSException raise:format:] + 139
3 Foundation 0x010ebba1 -[NSMutableRLEArray replaceObjectsInRange:withObject:length:] + 136
4 Foundation 0x010ebb14 -[NSMutableRLEArray deleteObjectsInRange:] + 63
5 Foundation 0x010ea559 -[NSConcreteMutableAttributedString replaceCharactersInRange:withAttributedString:] + 324
6 UIFoundation 0x02d9d9f4 __71-[NSConcreteTextStorage replaceCharactersInRange:withAttributedString:]_block_invoke + 68
7 UIFoundation 0x02d9d92f -[NSConcreteTextStorage replaceCharactersInRange:withAttributedString:] + 121
8 UIKit 0x00924d22 __53-[UITextInputController setMarkedText:selectedRange:]_block_invoke + 352
9 UIFoundation 0x02d9b491 -[NSTextStorage coordinateEditing:] + 48
10 UIKit 0x00924a38 -[UITextInputController setMarkedText:selectedRange:] + 249
11 UIKit 0x008fb3b1 -[UITextView setMarkedText:selectedRange:] + 63
12 UIKit 0x00644aa5 -[UIResponder(UITextInput_Internal) _setMarkedText:selectedRange:] + 101
13 UIKit 0x004031aa -[UIKeyboardImpl setMarkedText:selectedRange:inputString:searchString:] + 365
14 UIKit 0x00419737 -[TIKeyboardOperationSetMarkedText(UIKeyboardImpl) main] + 178
15 Foundation 0x0118da69 -[__NSOperationInternal _start:] + 671
16 Foundation 0x0110a798 -[NSOperation start] + 83
17 UIKit 0x0040e08a -[UIKeyboardImpl updateCandidateDisplayAsyncWithCandidateSet:documentOperation:] + 188
18 UIKit 0x00419041 -[TIKeyboardOperationSetCandidates(UIKeyboardImpl) main] + 112
19 Foundation 0x0118da69 -[__NSOperationInternal _start:] + 671
20 Foundation 0x0110a798 -[NSOperation start] + 83
21 UIKit 0x0040671d -[UIKeyboardImpl performOperations:] + 153
22 UIKit 0x00404f4e -[UIKeyboardImpl continueGenerateCandidatesAsynchronouslyWithOperations:] + 40
23 UIKit 0x00404c51 __87-[UIKeyboardImpl replyHandlerForGenerateCandidatesAsynchronouslyWithSelectedCandidate:]_block_invoke_2 + 46
24 UIKit 0x009381b8 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 402
25 UIKit 0x0093885f -[UIKeyboardTaskQueue addTask:] + 144
26 CoreFoundation 0x01729d1d __invoking___ + 29
27 CoreFoundation 0x01729c2a -[NSInvocation invoke] + 362
28 UIKit 0x008e63d2 -[_UIActionWhenIdle invoke] + 100
29 UIKit 0x008e64a6 __41-[_UIActionWhenIdle addObserverToRunLoop]_block_invoke + 36
30 CoreFoundation 0x0172924d _runLoopObserverWithBlockContext + 29
31 CoreFoundation 0x016fd53e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
32 CoreFoundation 0x016fd48f __CFRunLoopDoObservers + 399
33 CoreFoundation 0x016db3b4 __CFRunLoopRun + 1076
34 CoreFoundation 0x016dab33 CFRunLoopRunSpecific + 467
35 CoreFoundation 0x016da94b CFRunLoopRunInMode + 123
36 GraphicsServices 0x036d69d7 GSEventRunModal + 192
37 GraphicsServices 0x036d67fe GSEventRun + 104
38 UIKit 0x0022b94b UIApplicationMain + 1225
39 Test2 0x0000388d main + 141
40 libdyld.dylib 0x01d7370d start + 1
41 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
In addition, I test the following code, it also crashes after input "rr" with Chinese input keyboard.
-(void)textViewDidChange:(UITextView *)textView{
int maxLength = 2;
if (self.tv.text.length > maxLength) {
self.tv.text = #"c";
}
}
Any help will be appreciated!
What's happening is that you're typing what is referred to as multistage text input, i.e. the input has to be confirmed from the user before it's actually committed into the underlying text. You get the crash because the text is only kind-of inputted, and until the text has been committed, it could easily change to something else.
To detect this situation, you're looking for the markedTextRange property of the UITextView, which indicates if you're in this complex input mode.
If the property is non-nil, then you're in this special input mode, so you should guard your modification code with something like:
if (self.tv.markedTextRange == nil && self.tv.text.length > maxLength) {
// Perform change
}
Near as I can tell the crash is triggered by the special multistage text input mode, so you should avoid changing the text while this mode is active.
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]]) {
...
}
I'm trying to take an input string and return a new string that is encoded/decoded based on a dictionary that I created. I have tried the below code using instance variables and local variables. I am having a problem using the for loop. I get out of scope errors. When I use an instance variable for newText, I get a exec bad address when I try to assign the dictionaries value to it. When I declare newText in the method, I get out of scope errors.
- (NSString *) decodeText:(NSString *)text {
NSString *parseString = text;
NSLog(#"Letterdictionary = %#",lettersDictionary);
NSInteger y = [parseString length];
NSMutableString *newText = [NSMutableString stringWithCapacity:[parseString length]];
for (int x=0; x < y; x++) {
NSRange Range = NSMakeRange(x, 1);
NSString *myChar = [parseString substringWithRange:Range];
NSLog(#"Mychar =:%#",myChar);
[newText appendString:[lettersDictionary objectForKey:myChar]];
NSLog(#"newtext=%#",newText);
}
NSLog(#"NewText=%#",newText);
return newText;
}
here is the output from the debugger:
2010-08-21 07:59:27.151 GeoWordCalc[77460:207] Letterdictionary = {
N = A;
O = B;
P = C;
}
2010-08-21 07:59:47.891 GeoWordCalc[77460:207] Mychar =:A
2010-08-21 07:59:49.707 GeoWordCalc[77460:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString appendString:]: nil argument'
*** Call stack at first throw:
(
0 CoreFoundation 0x023df919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0252d5de objc_exception_throw + 47
2 CoreFoundation 0x02398078 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x02397fea +[NSException raise:format:] + 58
4 Foundation 0x000a585a mutateError + 156
5 GeoWordCalc 0x000050aa -[WordDecoder decodeText:] + 330
6 GeoWordCalc 0x00004cec -[DecoderViewController textFieldCharacterEntered] + 157
7 UIKit 0x003424b0 -[UIControl(D eprecated) sendAction:toTarget:forEvent:] + 67
8 UIKit 0x00344d81 -[UIControl(Internal) _sendActionsForEventMask:withEvent:] + 525
9 UIKit 0x0034a051 -[UITextField fieldEditorDidChange:] + 258
10 UIKit 0x003597f3 -[UIFieldEditor webViewDidChange:] + 76
11 Foundation 0x00022c1d _nsnote_callback + 145
12 CoreFoundation 0x023b7cf9 __CFXNotificationPost_old + 745
13 CoreFoundation 0x0233711a _CFXNotificationPostNotification + 186
14 Foundation 0x000187c2 -[NSNotificationCenter postNotificationName:object:userInfo:] + 134
15 CoreFoundation 0x0235042d __invoking___ + 29
16 CoreFoundation 0x02350301 -[NSInvocation invoke] + 145
17 WebCore 0x02e6277a _ZL19SendDelegateMessageP12NSInvocation + 602
18 WebKit 0x03c0b72f _ZN15WebEditorClient24respondToChangedContentsEv + 63
19 WebCore 0x02ee889c _ZN7WebCore6Editor14appliedEditingEN3WTF10PassRefPtrINS_11EditCommandEEE + 460
20 WebCore 0x036bdb9b _ZN7WebCore13TypingCommand24typingAddedToOpenCommandENS0_14ETypingCommandE + 75
21 WebCore 0x02ee312f _ZN7WebCore13TypingCommand28insertTextRunWithoutNewlinesERKNS_6StringEb + 159
22 WebCore 0x02ee306b _ZN7WebCore13TypingCommand10insertTextERKNS_6StringEb + 331
23 WebCore 0x02ee2eb6 _ZN7WebCore13TypingCommand7doApplyEv + 182
24 WebCore 0x02ee2c58 _ZN7WebCore11EditCommand5applyEv + 248
25 WebCore 0x02ee1c95 _ZN7WebCore13TypingCommand10insertTextEPNS_8DocumentERKNS_6StringERKNS_16VisibleSelectionEbb + 1525
26 WebCore 0x02ee1058 _ZN7WebCore6Editor33insertTextWithoutSendingTextEventERKNS_6StringEbPNS_5EventE + 1048
27 WebCore 0x02ee0c15 _ZN7WebCore12EventHandler28defaultTextInputEventHandlerEPNS_9TextEventE + 197
28 WebCore 0x02eb4548 _ZN7WebCore4Node19defaultEventHandlerEPNS_5EventE + 152
29 WebCore 0x02eb42a8 _ZN7WebCore4Node20dispatchGenericEventEN3WTF10PassRefPtrINS_5EventEEE + 1016
30 WebCore 0x02eb3e39 _ZN7WebCore4Node13dispatchEventEN3WTF10PassRefPtrINS_5EventEEE + 217
31 WebCore 0x02ee0ae0 _ZN7WebCore11EventTarget13dispatchEventEN3WTF10PassRefPtrINS_5EventEEERi + 112
32 WebCore 0x02ee07e1 _ZN7WebCore12EventHandler20handleTextInputEventERKNS_6StringEPNS_5EventEbb + 225
33 WebCore 0x02ee06f9 _ZN7WebCore6Editor10insertTextERKNS_6StringEPNS_5EventE + 57
34 WebKit 0x03c0af07 -[WebHTMLView(WebNSTextInputSupport) insertText:] + 951
35 WebCore 0x02ee0594 -[WAKResponder tryToPerform:with:] + 84
36 WebKit 0x03c0a9b3 -[WebView(WebViewEditingActions) _performResponderOperation:with:] + 147
37 WebKit 0x03c0a910 -[WebView(WebViewEditingActions) insertText:] + 48
38 UIKit 0x003f32db -[UIKeyboardImpl addInputString:fromVariantKey:] + 3251
39 UIKit 0x003f4a1a -[UIKeyboardImpl handleKeyEvent:] + 1918
40 UIKit 0x005151c0 -[UIKeyboardLayoutStar sendStringAction:forKey:] + 684
41 UIKit 0x005199ba -[UIKeyboardLayoutStar touchUp:] + 2556
42 UIKit 0x0040b9a3 -[UIKeyboardLayout touchesEnded:withEvent:] + 550
43 UIKit 0x002dc2ff -[UIWindow _sendTouchesForEvent:] + 567
44 UIKit 0x002be1ec -[UIApplication sendEvent:] + 447
45 UIKit 0x002c2ac4 _UIApplicationHandleEvent + 7495
46 GraphicsServices 0x02c45afa PurpleEventCallback + 1578
47 CoreFoundation 0x023c0dc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
48 CoreFoundation 0x02321737 __CFRunLoopDoSource1 + 215
49 CoreFoundation 0x0231e9c3 __CFRunLoopRun + 979
50 CoreFoundation 0x0231e280 CFRunLoopRunSpecific + 208
51 CoreFoundation 0x0231e1a1 CFRunLoopRunInMode + 97
52 GraphicsServices 0x02c442c8 GSEventRunModal + 217
53 GraphicsServices 0x02c4438d GSEventRun + 115
54 UIKit 0x002c6b58 UIApplicationMain + 1160
55 GeoWordCalc 0x000027c4 main + 102
56 GeoWordCalc 0x00002755 start + 53
)
terminate called after throwing an instance of 'NSException'
Okay..so after a night's sleep and more debugging I figured out that I lettersDictionary was returning a null value. It seems I build the dictionary backwards...sorry and thanks.