For example, I get this error in debug area:
2014-05-01 05:01:28.052 MyApp[93187:303] *** setObjectForKey: object cannot be nil (key: -1)
2014-05-01 05:01:28.057 MyApp[93187:303] (
0 CoreFoundation 0x00007fff8cb3f25c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff89202e75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8ca3a46e -[__NSDictionaryM setObject:forKey:] + 1102
3 MyApp 0x0000000100009725 +[SystemTools getData:] + 5509
4 MyApp 0x0000000100001c4b -[AppDelegate drawCanvas:] + 1467
5 MyApp 0x0000000100001675 -[AppDelegate repeatingTimer:] + 85
6 Foundation 0x00007fff8ec480f4 __NSFireTimer + 96
7 CoreFoundation 0x00007fff8caa6564 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
8 CoreFoundation 0x00007fff8caa609f __CFRunLoopDoTimer + 1151
9 CoreFoundation 0x00007fff8cb175aa __CFRunLoopDoTimers + 298
10 CoreFoundation 0x00007fff8ca618e5 __CFRunLoopRun + 1525
11 CoreFoundation 0x00007fff8ca610b5 CFRunLoopRunSpecific + 309
12 HIToolbox 0x00007fff875dca0d RunCurrentEventLoopInMode + 226
13 HIToolbox 0x00007fff875dc7b7 ReceiveNextEventCommon + 479
14 HIToolbox 0x00007fff875dc5bc _BlockUntilNextEventMatchingListInModeWithFilter + 65
15 AppKit 0x00007fff907853de _DPSNextEvent + 1434
16 AppKit 0x00007fff90784a2b -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
17 AppKit 0x00007fff90778b2c -[NSApplication run] + 553
18 AppKit 0x00007fff90763913 NSApplicationMain + 940
19 MyApp 0x0000000100016aa2 main + 34
20 libdyld.dylib 0x00007fff9440b5fd start + 1
21 ??? 0x0000000000000003 0x0 + 3
)
Unfortunately, I have saveral "setObject:forKey:" calls in "SystemTools getData:" function.
How can I determine to which call this error is related? What that numbers (after plus) means?
Add an Execption breakpoint in your break points. This will halt at the line of code which is causing the app to crash. That way you dont have to debug with NSLogs.
The default behavior of Xcode is to stop where the exception is
caught, not where the exception is raised!
To explain those lines in the crash logs:
From Ray Wenderlich's blog:
2 XYZLib 0x34648e88 0x83000 + 8740
It is basically four columns:
The frame number – in this case, 2.
The name of the binary – in this case, XYZLib.
The address of the function that was called – in this case, 0x34648e88.
The fourth column is divided into two sub-columns, a base address and an offset. Here it is 0×83000 + 8740, where the first number points to the file, and the second points to the line of code in that file.
Use breakpoints in all of your setObject:forKey calls. Use NSLog for print some useful information in log. You are a developer so you need to know debugging also.
The first line of the output is useful here:
setObjectForKey: object cannot be nil (key: -1)
The NSDictionary doesn't like nil values, so look for a place in your getData method that could be assigning a nil value to a key of "-1".
Good luck!
Related
I have a simple Mac application that receives the following error when opening a document:
Failed to set (allowsDragging) user defined inspected property on (PKMPDFView): [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key allowsDragging.
If I intercept the "set" attempt, I see that it originates from the method -[NSIBUserDefinedRuntimeAttributesConnector establishConnection] during nib loading.
Full trace:
0 PDFApp 0x0000000100003592 -[PKMPDFView setValue:forUndefinedKey:] + 49
1 Foundation 0x00007fff309b8dde -[NSObject(NSKeyValueCoding) setValue:forKey:] + 331
2 AppKit 0x00007fff2c08af15 -[NSView setValue:forKeyPath:] + 394
3 AppKit 0x00007fff2c00d029 -[NSIBUserDefinedRuntimeAttributesConnector establishConnection] + 637
4 AppKit 0x00007fff2bdd9719 -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1430
5 AppKit 0x00007fff2bdd0991 loadNib + 435
6 AppKit 0x00007fff2bdcfeb5 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 696
7 AppKit 0x00007fff2c005aba +[NSBundle(NSNibLoadingInternal) _loadNibFile:externalNameTable:options:withZone:] + 150
8 AppKit 0x00007fff2c005893 -[NSWindowController loadWindow] + 322
9 AppKit 0x00007fff2be18cf5 -[NSWindowController window] + 84
10 AppKit 0x00007fff2bfd8134 -[NSWindowController showWindow:] + 36
11 AppKit 0x00007fff2be18c7a -[NSDocument showWindows] + 116
12 PDFApp 0x0000000100002e75 -[PKMPDFDocument showWindows] + 50
13 AppKit 0x00007fff2c35f13e __80-[NSDocumentController openDocumentWithContentsOfURL:display:completionHandler:]_block_invoke.1039 + 182
14 AppKit 0x00007fff2c36ef70 ___NSMainRunLoopPerformBlock_block_invoke + 25
15 CoreFoundation 0x00007fff2e897a3c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
16 CoreFoundation 0x00007fff2e87a973 __CFRunLoopDoBlocks + 275
17 CoreFoundation 0x00007fff2e879ffe __CFRunLoopRun + 1278
18 CoreFoundation 0x00007fff2e879867 CFRunLoopRunSpecific + 487
19 HIToolbox 0x00007fff2db59d96 RunCurrentEventLoopInMode + 286
20 HIToolbox 0x00007fff2db59b06 ReceiveNextEventCommon + 613
21 HIToolbox 0x00007fff2db59884 _BlockUntilNextEventMatchingListInModeWithFilter + 64
22 AppKit 0x00007fff2be09a73 _DPSNextEvent + 2085
23 AppKit 0x00007fff2c59fe34 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
24 AppKit 0x00007fff2bdfe885 -[NSApplication run] + 764
25 AppKit 0x00007fff2bdcda72 NSApplicationMain + 804
26 libdyld.dylib 0x00007fff56848015 start + 1
What confuses me is that PKMPDFView is a direct subclass of NSView and has no user defined properties associated with it in the .xib file being loaded. This view also has no outlets defined in the .xib, just a referencing outlet (contentView) from its document. Running find/grep through my development directory finds no instance of "allowsDragging" anywhere. Likewise, using the strings utility reveals no "allowsDragging" in the built app.
I've tried all the standard project cleaning with no change in symptoms.
At the moment, I'm tempted to simply override setValue:forUndefinedKey: and forget it but I'm still curious. Does anyone have information or good guesses about where this would be coming from?
(This is Xcode 10.1 on macOS 10.13.6, in case that matters.)
A lot of crash reports coming in with this theme. What could be causing this? It's never in the same place twice. I am using AQXMLParser but the crashes are always in some place unconnected to that. I'm not looking for help to diagnose the specific cause of this issue, Seems like some bad memory management in the XML parser delegate (written before I came onboard). So my question: Is there is some class of programming error that would exhibit this behavior? I'd like to learn so I know what to look for in the future.
0 <MY APPLICATION> ✭ <SOME RANDOM CLASS THAT HAS NOTHING TO DO WITH XML PARSING>.m line 687
-[<SOME RANDOM THAT HAS NOTHING TO DO WITH XML PARSING>:] + 687
1
...
libxml2.2.dylib
__xmlRaiseError + 898
2 libxml2.2.dylib
xmlFatalErr + 952
3 libxml2.2.dylib
xmlParseEntityRef + 104
4 libxml2.2.dylib
xmlParseReference + 270
5 libxml2.2.dylib
xmlParseTryOrFinish + 1422
6 libxml2.2.dylib
xmlParseChunk + 212
7 MyApplication AQXMLParser.m line 1238
-[AQXMLParser stream:handleEvent:] + 1238
8 CoreFoundation
_signalEventSync + 74
9 CoreFoundation
_cfstream_shared_signalEventSync + 240
10
...
CoreFoundation
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
11 CoreFoundation
__CFRunLoopDoSources0 + 212
12 CoreFoundation
__CFRunLoopRun + 646
13 CoreFoundation
CFRunLoopRunSpecific + 356
14 CoreFoundation
CFRunLoopRunInMode + 104
15 Foundation
-[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 254
16 MyApplication AQXMLParser.m line 1115
-[AQXMLParser inputRunRunLoopInMode:] + 1115
17 MyApplication AQXMLParser.m line 1164
This turned out to be a bug in an old version of AQXMLParser. Updating to the latest fixed it.
I only replace the video files in my existing code, but if i replace all the video files my application will crash in iphone. it is an universal application but Ipad support all the new video files and crash on iphone. the following warning occur:
[NSCFType setLength:]: unrecognized selector sent to instance
0x19d790 2012-02-29 15:13:49.932[584:307] * Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType
setLength:]: unrecognized selector sent to instance 0x19d790'
* Call stack at first throw: ( 0 CoreFoundation 0x3759dc7b __exceptionPreprocess + 114 1 libobjc.A.dylib
0x32d9bee8 objc_exception_throw + 40 2 CoreFoundation
0x3759f3e3 -[NSObject(NSObject) doesNotRecognizeSelector:] + 98 3
CoreFoundation 0x37544467 __forwarding + 506
4 CoreFoundation 0x37544220
_CF_forwarding_prep_0 + 48 5 Visionaries 0x00005179 -[Visionaries_ViewController
connection:didReceiveResponse:] + 56 6 Foundation
0x35183cd5 -[NSURLConnection(NSURLConnectionReallyInternal)
sendDidReceiveResponse:] + 92 7 Foundation
0x35183c3b _NSURLConnectionDidReceiveResponse + 86 8 CFNetwork
0x302941b4
_ZN19URLConnectionClient29_clientSendDidReceiveResponseEP14_CFURLResponsePNS_26ClientConnectionEventQueueE
+ 64 9 CFNetwork 0x30284bc8 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl
+ 332 10 CFNetwork 0x30284d84 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl
+ 776 11 CFNetwork 0x30284984 _ZN19URLConnectionClient13processEventsEv + 100 12 CFNetwork 0x3028484c _ZN17MultiplexerSource7performEv + 192 13 CFNetwork
0x30284788 _ZN17MultiplexerSource8_performEPv + 12 14 CoreFoundation
0x375518d1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION
+ 14 15 CoreFoundation 0x37521ecd __CFRunLoopDoSources0 + 384 16 CoreFoundation 0x375216f9 __CFRunLoopRun + 264 17 CoreFoundation
0x3752150b CFRunLoopRunSpecific + 226 18 CoreFoundation
0x37521419 CFRunLoopRunInMode + 60 19 GraphicsServices
0x33e76d24 GSEventRunModal + 196 20 UIKit
0x3591d57c -[UIApplication _run] + 588 21 UIKit
0x3591a558 UIApplicationMain + 972 22 Visionaries
0x00002391 main + 80 23 Visionaries
0x0000233c start + 40 ) terminate called after throwing an instance of
'NSException'
Somebody has an idea, please help.
By the crash log we see that, inside -[Visionaries_ViewController connection:didReceiveResponse:], you are calling the method setLength: on an object that does not have that method.
Can be a memory or logic problem. Please provide more info.
I am new to iphone developement, during development I face problem due to this error. I am unable to trace it that from where it is produced.
app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 5 beyond bounds [0 .. 4]'
*** Call stack at first throw:
(
0 CoreFoundation 0x012dcbe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x014315c2 objc_exception_throw + 47
2 CoreFoundation 0x012d26e5 -[__NSArrayM objectAtIndex:] + 261
3 Dispatch 0x0002feeb -[ZoneFareTaxi parseMessage:] + 754
4 Dispatch 0x0002fbf0 -[ZoneFareTaxi initWithMessageString:] + 92
5 Dispatch 0x0003b949 -[ServerConnection onUdpSocket:didReceiveData:withTag:fromHost:port:] + 8862
6 Dispatch 0x0002350e -[AsyncUdpSocket maybeCompleteCurrentReceive] + 458
7 Dispatch 0x00023210 -[AsyncUdpSocket doReceive:] + 1364
8 Dispatch 0x00022c60 -[AsyncUdpSocket doReceive4] + 80
9 Dispatch 0x00022add -[AsyncUdpSocket maybeDequeueReceive] + 561
10 Foundation 0x000da7f6 __NSFireDelayedPerform + 441
11 CoreFoundation 0x012bdfe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
12 CoreFoundation 0x012bf594 __CFRunLoopDoTimer + 1220
13 CoreFoundation 0x0121bcc9 __CFRunLoopRun + 1817
14 CoreFoundation 0x0121b240 CFRunLoopRunSpecific + 208
15 CoreFoundation 0x0121b161 CFRunLoopRunInMode + 97
16 GraphicsServices 0x01a4d268 GSEventRunModal + 217
17 GraphicsServices 0x01a4d32d GSEventRun + 115
18 UIKit 0x0036a42e UIApplicationMain + 1160
19 Dispatch 0x000024b4 main + 102
20 Dispatch 0x00002445 start + 53
21 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
This is likely an off by one error. Your NSMutableArray has only 5 elements and you are accessing the 6th object at index 5. Indexes are 0 based.
The problem resides likely in this method: [ZoneFareTaxi parseMessage:]
It should be in the parseMessage method implementation, of the class ZoneFareTaxi.
In that method you send the message objectAtIndex: to an NSMutableArray object, passing a value that in that case is 5 (presumably using a variable).
It says that you are accessing to the sixth element of the array, while it has only 5 elements. Arrays are 0 indexed.
this problem only appears only if your trying to access an element from array with index is greater than your count of array.
From this:
-[NSMutableArray objectAtIndex:]: index 5 beyond bounds [0 .. 4]
you can see that you're trying to access index 5 in an array that only goes from 0 to 4.
From this:
objc_exception_throw + 47
-[__NSArrayM objectAtIndex:] + 261
-[ZoneFareTaxi parseMessage:] + 754
you can see that the problem is happening in your [ZoneFareTaxi parseMessage:] method.
I am using xcode Instruments to track Allocations and Leaks. My app is crashing though. It does not crash when running the regular debug or release builds standalone, only when under Instruments:
Any thoughts ideas very gratefully received....
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0002b2e0
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x34499c96 objc_msgSend + 14
1 ZZZ Test Suite 0x000a3d74 0x95000 + 60788
2 CoreFoundation 0x308e4c3c -[NSObject(NSObject) release] + 24
3 CoreFoundation 0x308e519a CFRelease + 62
4 CoreFoundation 0x308e7eb4 _CFAutoreleasePoolPop + 140
5 Foundation 0x341b41c4 -[NSAutoreleasePool release] + 92
6 UIKit 0x309e5f08 _UIApplicationHandleEvent + 5784
7 GraphicsServices 0x30269e70 PurpleEventCallback + 660
8 CoreFoundation 0x30957a90 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 20
9 CoreFoundation 0x30959838 __CFRunLoopDoSource1 + 160
10 CoreFoundation 0x3095a606 __CFRunLoopRun + 514
11 CoreFoundation 0x308eaebc CFRunLoopRunSpecific + 224
12 CoreFoundation 0x308eadc4 CFRunLoopRunInMode + 52
13 GraphicsServices 0x30269418 GSEventRunModal + 108
14 GraphicsServices 0x302694c4 GSEventRun + 56
15 UIKit 0x30a10d62 -[UIApplication _run] + 398
16 UIKit 0x30a0e800 UIApplicationMain + 664
17 ZZZ Test Suite 0x0009665c 0x95000 + 5724
18 ZZZ Test Suite 0x00096604 0x95000 + 5636
Try running it through the analyser first. You can run it from xcode from the |product| menu then select Analyze. It's a static analyser (clang) that analyses your code when it builds so any problems causing your code to crash at runtime could well be visible through static analysis. Give it a try and fix any problems it throws up then try instruments again.
As a complement to what Ian says above:
set the Environment variable "NSZombieEnabled" to YES
and you will hopefully have a more informative fail.
(In XCode 4 the Environment Variables is found under "Edit Scheme" and select "Debug")