Can't figure out "Unrecognized selector sent to instance" source - objective-c

So I am at my wit's end on this, I am toggling some sharedprefs back and forth, and eventually it makes my app crash. I thought it was because I wasn't deallocating observers properly, but upon looking at the crash log it says that an unrecognized selector is sent to instance. Does anybody know more about crash logs that can tell me more about what's happening? I can get the basic gist of what's happening out of the log, but I'm still a rookie and a lot of the information is going over my head.
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType _adjustLengthDueToViewFrameChange:]: unrecognized selector sent to instance 0x608000095b80'
terminating with uncaught exception of type NSException
abort() called
Application Specific Backtrace 1:
0 CoreFoundation 0x00007fff8fdcb25c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff92afae75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8fdce12d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff8fd29272 ___forwarding___ + 1010
4 CoreFoundation 0x00007fff8fd28df8 _CF_forwarding_prep_0 + 120
5 CoreFoundation 0x00007fff8fd99e0c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
6 CoreFoundation 0x00007fff8fc8d82d _CFXNotificationPost + 2893
7 AppKit 0x00007fff915a4003 -[NSView _postFrameChangeNotification] + 434
8 AppKit 0x00007fff915ad6c2 -[NSView setFrameSize:] + 1586
9 AppKit 0x00007fff915ad049 -[NSView setFrame:] + 294
10 AppKit 0x00007fff915acc2b -[NSWindow setContentView:] + 453
11 AppKit 0x00007fff91beeace -[NSStatusItem setView:] + 224
12 MyAppHelper 0x00000001000775f5 -[NSStatusItem(BCStatusItem) setupView] + 85
13 MyAppHelper 0x000000010000cdbb -[MyAppHelperCapHelperServer createStatusBarItem] + 299
14 MyAppHelper 0x000000010000cf5b -[MyAppHelperCapHelperServer insertCaptureMenu] + 43
15 MyAppHelper 0x000000010000fe3d -[MyAppHelperHelperServer observeValueForKeyPath:ofObject:change:context:] + 733
16 Foundation 0x00007fff927e8f28 NSKeyValueNotifyObserver + 387
17 Foundation 0x00007fff927e80f8 NSKeyValueDidChange + 453
18 Foundation 0x00007fff927ecbe6 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 118
19 MyAppHelperHelper 0x0000000100109a3d __57-[RMSharedUserDefaults __applyBaselineAndNotify:updates:]_block_invoke + 349
20 CoreFoundation 0x00007fff8fd086df __65-[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 111
21 CoreFoundation 0x00007fff8fd085ee -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 222
Primarily, I have no idea what it means in the exception information: [__NSCFType _adjustLengthDueToViewFrameChange:]. I cannot seem to find any information anywhere.
Thanks in advance!

First, I assume you are manually managing the memory, if so, I'll Highly recommend you to migrate to ARC (Automatic Reference Counting) it will manage the memory for you and you wont have this type or errors anymore. There are plenty of tutorials on Google of how to do this.
You can read more here: Transitioning to ARC Release Notes
Second, without ARC, this kind of error is often caused because you are calling a method/selector on an already released object, that's why the method/selector is not recognized.
This assuming you take care of clearing all the warnings on your project, if not, first go and check if there isn't a warning already pointing that you are trying to call a method/selector that doesn't exist for some object in your app. You can use the Analyze option as mentioned on the comments of this answer. To do that just Cmd+Shift+b, select the Analyze option from the Product Menu or Press and Hold the "Play" button you use to build the app and you will see the Analyze option as well.
Finally, I see you are using User Defaults. I'll recommend making sure you are retaining the values you are receiving from the User Defaults as they came with autorelease. This will explain why the compiler is not able to show the exact line of code where this error is happening, because it happens until the objet is autoreleased.
If is not the User Defaults I'll go and check all my autoreleased variables, is most likely that the problem is with one of them.

Related

Tracking down a SIGSEGV…

So I've got this weird SIGSEGV happening at very few (less than 1%) of my users…
From the stack trace it looks like an over-release
Thread 0 Crashed:
0 libobjc.A.dylib 0x00007fff9a3f916f objc_release + 31
1 libobjc.A.dylib 0x00007fff9a3f7ac4 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 475
2 CoreFoundation 0x00007fff9cc5c102 _CFAutoreleasePoolPop + 49
3 Foundation 0x00007fff96992cb6 -[NSAutoreleasePool drain] + 152
4 AppKit 0x00007fff9138409b -[NSApplication run] + 892
5 AppKit 0x00007fff91306520 NSApplicationMain + 1175
6 RailModeller Pro 0x000000010b60578b main (main.m:30)
7 libdyld.dylib 0x00007fff9a36b5ad start + 0
..but no matter what I try,
even with the very same data,
following the exact same steps as the users,
same OS/patch level,
using Address Sanitizer (Xcode 7.3),
using Zombies instrument,
using Guard Malloc
all appears to be fine.
The function crashing is a pretty common one in the app and I'd be drowning in bug reports (both from the automated bug reporting system as well as users getting in touch) if this were a more common issue.
However, to these (<1%) users the app appears effectively unusable.
Any hints on how to track down this issue much appreciated!

I used UICollectionViewFlowLayout category and my app crash sometimes with PhotosUI

I don't use PhotosUI framework in any place of my app .Don't know why I got crash report from PhotosUI .
Here is crash report from Crashlytics .
0 CoreFoundation __exceptionPreprocess + 130
1 libobjc.A.dylib objc_exception_throw + 38
2 CoreFoundation -[NSObject(NSObject) doesNotRecognizeSelector:] + 202
3 CoreFoundation ___forwarding___ + 706
4 CoreFoundation _CF_forwarding_prep_0 + 24
5 MyApp UICollectionViewFlowLayout+NoFade.m line 42
-[UICollectionViewFlowLayout(NoFade)noFadeFinalLayoutAttributesForDisappearingItemAtIndexPath:]
6 PhotosUI -[PUSectionedGridLayout finalLayoutAttributesForDisappearingItemAtIndexPath:]
-[PUSectionedGridLayout noFadeFinalLayoutAttributesForDisappearingItemAtIndexPath:]: unrecognized selector sent to instance 0x16d56160
It crashed because my UICollectionViewFlowLayout+NoFade tried to call noFadeFinalLayoutAttributesForDisappearingItemAtIndexPath
which is not available PUSectionedGridLayout
But I didn't use PUSectionedGridLayout in any of my code. Is it happen when users select to pick photo from album or something ? I am not able to reproduct this crashes. Any solution for this ?
Thanks
PUSectionedGridLayout looks to be part of the photos UI internals so it would not be a surprise that it is in your call stack if you were using the photos UI.
https://github.com/EthanArbuckle/IOS-7-Headers/blob/master/PrivateFrameworks/PhotosUI.framework/PUSectionedGridLayout.h
However, since you say you are not, at least not directly, the questions is could it be coming in indirectly via either a third party library or an image picker flow?

Having trouble with a Crash Report - EXC_BAD_ACCESS

OK, SO I've received a crash report for one of my apps, but I swear I'm 100% confused.
This is what the "core" part of it looks like :
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000
VM Regions Near 0:
-->
__TEXT 0000000100000000-0000000100015000 [ 84K] r-x/rwx SM=COW /Applications/MY_APP/Contents/MacOS/MY_APP
Application Specific Information:
objc[337]: garbage collection is ON
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_c.dylib 0x00007fff90128650 strlen + 16
1 MY_BUNDLE_ID 0x0000000100008f12 0x100000000 + 36626
2 MY_BUNDLE_ID 0x000000010000b435 0x100000000 + 46133
3 MY_BUNDLE_ID 0x0000000100003c90 0x100000000 + 15504
4 com.apple.CoreFoundation 0x00007fff9065147a _CFXNotificationPost + 2554
5 com.apple.Foundation 0x00007fff8e5fe846 -[NSNotificationCenter postNotificationName:object:userInfo:] + 64
6 com.apple.AppKit 0x00007fff9a7894a7 -[NSTableView textDidChange:] + 377
7 com.apple.CoreFoundation 0x00007fff9065147a _CFXNotificationPost + 2554
8 com.apple.Foundation 0x00007fff8e5fe846 -[NSNotificationCenter postNotificationName:object:userInfo:] + 64
9 com.apple.AppKit 0x00007fff9a15c260 -[NSTextView(NSSharing) didChangeText] + 339
10 com.apple.AppKit 0x00007fff9a7f8381 _NSDoUserReplaceForCharRange + 390
11 com.apple.AppKit 0x00007fff9a7f85b1 _NSDoUserDeleteForCharRange + 38
12 com.apple.AppKit 0x00007fff9a7e1e72 -[NSTextView(NSKeyBindingCommands) deleteBackward:] + 440
13 com.apple.AppKit 0x00007fff9a18a1cc -[NSResponder doCommandBySelector:] + 75
14 com.apple.AppKit 0x00007fff9a18a02e -[NSTextView doCommandBySelector:] + 197
15 com.apple.AppKit 0x00007fff9a20cf4e -[NSKeyBindingManager(NSKeyBindingManager_MultiClients) interpretEventAsCommand:forClient:] + 2200
16 com.apple.AppKit 0x00007fff9a20c3bb -[NSTextInputContext handleEvent:] + 939
17 com.apple.AppKit 0x00007fff9a20bf87 -[NSView interpretKeyEvents:] + 183
18 com.apple.AppKit 0x00007fff9a158f67 -[NSTextView keyDown:] + 723
19 com.apple.AppKit 0x00007fff9a374120 -[NSWindow sendEvent:] + 9687
20 com.apple.AppKit 0x00007fff9a36f744 -[NSApplication sendEvent:] + 5761
21 com.apple.AppKit 0x00007fff9a2852fa -[NSApplication run] + 636
22 com.apple.AppKit 0x00007fff9a229cb6 NSApplicationMain + 869
23 MY_BUNDLE_ID 0x0000000100002014 0x100000000 + 8212
Do you have any idea what might be going wrong?
Or could you just point me to the right direction?
As an aside :
Could anyone guide me how to make e.g. 0x00007fff90128650 more... meaningful and make it (in some future crash report) also show the name of the function?
Your crash log give you lot of informations:
first you crashed because you tried to access to address 0 into ur program and kernel is not happy.
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000
See, you get a segmentation, by the way it's starting to the 0x00 address, so it's like you're directly accessing a 0 / nil pointer.
Like this
char* adress = 0;
printf("get %p", adress); // will output 0x0
printf("get %p", adress[0]); // will make a EXC_BAD_ACCESS
You should really focus on this.
From the crash stack there is three interesting things:
6 com.apple.AppKit 0x00007fff9a7894a7 -[NSTableView textDidChange:] + 377
5 com.apple.Foundation 0x00007fff8e5fe846 -[NSNotificationCenter postNotificationName:object:userInfo:] + 64
0 libsystem_c.dylib 0x00007fff90128650 strlen + 16
[textDidChange] is one of the last call who caused the crash, by the way you're sending a notification when the [textDidChange] is fired. And last line who actually make the crash: strlen + 16 is because there's something who think it can get a char length from a valid pointer address and it's actually not the case.
According to me, you should check what you're sending into your notification.
_NSDoUserReplaceForCharRange
_NSDoUserDeleteForCharRange
When you look deeply into the stack crash, it really seems that's it's appearing when you make cell - insertion / deletion into ur tableViewController. You should check that sometime someone push invalid data, or not using the edit cell the way it's supposed to be.
So here's the resume:
1 Someone edit a tableViewCell, he doesn't insert or code doesn't insert what it's supposed to be.
2 You're sending a notification with a non-valid data inside it.
3 When the strlen(invalid_dataStructure) is fired, it make ur app crash
By the way i'm just "guessing", since i don't know actually your code implementation. But i hope it can give you lots of clues for your debugging session.
Usually the problem is that you need a "retain" property.
You need to enable Zombies for debug mode.
in xCode 4 click "edit scheme"->"Diagnostics"->"Enable Zombie Objects"
It will show you in console what "removed" object you try to access when crashing.
this should help.
you will see somthing like this:
2010-01-25 14:35:24.840 MyApplication[1393:20b] *** -[CFString retain]: message sent to deallocated instance 0x42a5060
You can also enable "Malloc logging" and after crash enter such command in debug console:
shell malloc_history 1393 0x42a5060
there you can find all alloc/release stack. just look at release and alloc commands.
I got a very similar crash report trying to open graphic-heavy applications (pymol and coot) (See below)
I found out that if I disconnected my mac from my external monitor, the programs worked again. I was using a USB-HDMI connector - apparently this is a bad idea. I just purchased a microUSB-HDMI connector and I expect this will work better. The programs run if I just use my mac book's own monitor display.
Time Awake Since Boot: 19000 seconds
Time Since Wake: 110 seconds
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000
VM Regions Near 0:
-->
__TEXT 0000000100000000-0000000100cff000 [ 13.0M] r-x/rwx SM=COW /Applications/MacPyMOL.app/Contents/MacOS/MacPyMOL
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.apple.opengl 0x00007fff8333857c CGLDescribeRenderer + 79
1 com.schrodinger.macpymol 0x000000010083c5b4 CheckOpenGLCaps + 484
2 com.schrodinger.macpymol 0x000000010084cd8c -[PyMOLOpenGLView awakeFromNib] + 1420
3 com.apple.CoreFoundation 0x00007fff8a10785f -[NSSet makeObjectsPerformSelector:] + 223
4 com.apple.AppKit 0x00007fff88b935cd -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1216
5 com.apple.AppKit 0x00007fff886a3605 loadNib + 384
6 com.apple.AppKit 0x00007fff88c14749 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 727
7 com.apple.AppKit 0x00007fff88c14ca8 +[NSBundle(NSNibLoadingInternal) _loadNibFile:externalNameTable:options:withZone:] + 150
8 com.apple.AppKit 0x00007fff886a2bc0 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 631
9 com.schrodinger.macpymol 0x000000010084d77b main + 1499
10 com.schrodinger.macpymol 0x0000000100007494 start + 52

NSEvent charactersIgnoringModifiers randomly throws "TSMProcessRawKeyCode failed" exception

Our Mac cocos2d app (http://deepworldgame.com) has been randomly throwing "TSMProcessRawKeyCode failed" exceptions for some time now, and I'm wondering if anyone has experienced this error or knows how to prevent it.
It always happens via the [NSEvent charactersIgnoringModifiers] call within ccKeysDown or ccKeysUp (it also happens for [NSEvent characters] without the modifiers). I don't think it's related to specific keys. Sometimes it only happens one time and the app continues to function afterward (if the exception is caught), but other times it essentially locks up keyboard input indefinitely and continues to cause exceptions with all future keypresses (again, when these exceptions are caught).
I've found little on the internets regarding this issue, unfortunately. One place I did find was in the Adium source code (https://bitbucket.org/adium/adium/src/6d1f9b903525/Source/AIExceptionController.m), which catches this exception with the comments:
//Ignore various known harmless or unavoidable exceptions (From the system or system hacks)
...
// [TSMProcessRawKeyCode] May be raised by -[NSEvent charactersIgnoringModifiers]
It is indeed harmless when thrown once, but when the occasion happens that it continuously fires, it's a real problem - especially when you're in fullscreen mode and can't use cmd-F to escape!
So, if anyone has any thoughts or experience, I would be HIGHLY grateful. This is pretty much the one remaining superbug in our application, and I would love to squash it into dust.
Thanks!
Here is the typical stack trace (MacManager.m is our object which implements the cocos2d keyboard delegate protocol):
Crashed Thread: 7 CVDisplayLink
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Application Specific Information:
objc[28871]: garbage collection is OFF
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'TSMProcessRawKeyCode failed (-192)'
*** Call stack at first throw:
(
0 CoreFoundation 0x95b27d87 __raiseError + 231
1 libobjc.A.dylib 0x9315a149 objc_exception_throw + 155
2 CoreFoundation 0x95a8f619 +[NSException raise:format:arguments:] + 137
3 CoreFoundation 0x95a8f589 +[NSException raise:format:] + 57
4 AppKit 0x9ac01c1f _convertEventRefToString + 300
5 AppKit 0x9ab23b5e -[NSEvent charactersIgnoringModifiers] + 880
6 Deepworld 0x0001fd8a -[MacManager ccKeyDown:] + 65
7 CoreFoundation 0x95a7d091 -[NSObject performSelector:withObject:] + 65
8 Deepworld 0x0006bc95 -[CCEventDispatcher keyDown:] + 80
9 CoreFoundation 0x95a7d091 -[NSObject performSelector:withObject:] + 65
10 Deepworld 0x0006c014 -[CCEventDispatcher dispatchQueuedEvents] + 143
11 Deepworld 0x0006a9a4 -[CCDirectorDisplayLink getFrameForTime:] + 155
12 Deepworld 0x0006aaf1 MyDisplayLinkCallback + 40
13 CoreVideo 0x9b44a5e1 _ZN13CVDisplayLink9performIOEP11CVTimeStamp + 489
14 CoreVideo 0x9b4494e4 _ZN13CVDisplayLink11runIOThreadEv + 876
15 CoreVideo 0x9b449161 _ZL13startIOThreadPv + 160
16 libsystem_c.dylib 0x968a4ed9 _pthread_start + 335
17 libsystem_c.dylib 0x968a86de thread_start + 34
)
I don't think sending events in general is thread-safe, not to mention from a thread that has been created not within +[NSThread detachNewThreadSelector:toTarget:withObject:] (a thread created using the Objective-C run-time has __NSThread__main__ in the backtrace).
I guess your app is the Deepworld binary part - when dispatching events, try using -[NSObject performSelectorOnMainThread:waitUntilDone:] instead, dispatching the events on the main thread.

Core Data Utility Crash

I'm working through the Core Data Utility at http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CoreDataUtilityTutorial/Articles/00_introduction.html#//apple_ref/doc/uid/TP40001800-CH202-TP1
I've stumbled on a rather nasty crash SIG_ABRT on the line that reads:
[moc save:&error]
This is the output in the debug:
2010-07-25 22:24:01.665 CoreDataUtilityTutorial[1607:a0f] -[NSCFNumber timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x200022100
2010-07-25 22:24:01.666 CoreDataUtilityTutorial[1607:a0f] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x200022100'
*** Call stack at first throw:
(
0 CoreFoundation 0x00007fff87e71cc4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00007fff840ee0f3 objc_exception_throw + 45
2 CoreFoundation 0x00007fff87ecb140 +[NSObject(NSObject) doesNotRecognizeSelector:] + 0
3 CoreFoundation 0x00007fff87e43cdf ___forwarding___ + 751
4 CoreFoundation 0x00007fff87e3fe28 _CF_forwarding_prep_0 + 232
5 CoreData 0x00007fff881baede -[NSXMLDocumentMap getXMLAttributeValueFromObject:forAttribute:] + 478
6 CoreData 0x00007fff881be7c8 -[NSXMLDocumentMap nodeFromManagedObject:objectIDMap:] + 1160
7 CoreData 0x00007fff881bb67c -[NSXMLDocumentMap addObject:objectIDMap:] + 140
8 CoreData 0x00007fff8817d400 -[NSMappedObjectStore _addObject:objectIDMap:] + 32
9 CoreData 0x00007fff8817c98f -[NSMappedObjectStore executeSaveChangesRequest:withContext:] + 1343
10 CoreData 0x00007fff88177599 -[NSMappedObjectStore executeRequest:withContext:] + 105
11 CoreData 0x00007fff88145051 -[NSPersistentStoreCoordinator(_NSInternalMethods) executeRequest:withContext:] + 545
12 CoreData 0x00007fff88179123 -[NSManagedObjectContext save:] + 323
13 CoreDataUtilityTutorial 0x00000001000015b7 main + 303
14 CoreDataUtilityTutorial 0x0000000100000cac start + 52
15 ??? 0x0000000000000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Anyone have an idea? I rechecked the code to see if I mistyped something but nothing is wrong...
Thanks in advance.
Without your actual code, this is a wild stab in the dark, but it looks as if your store is improperly configured at some juncture. Specifically, it looks as if the runtime is expecting a date, but the store has a number.
This could result from making changes to a model without doing a full recompile, maybe.
It could of course be something completely different, but without your specific code, or at the very least a diff against the finished example project as supplied with the tutorial, this is pretty difficult to troubleshoot.
(Another, not impossible, alternative, is that the tutorial was written to assume a specific, earlier version of Mac OS X, like 10.4 or 10.5. This could also result in problems, especially if the default settings for a Core Data project has changed, and this is a result of using the XML store over, say, the SQLite store.)
Looks like the crash is somewhere in the XML code, not the core data code.