iOS: How to get stack trace of an unhandled std::exception? - iphone

If an unhandled NSException is thrown, the stack trace has a section like this:
Last Exception Backtrace:
0 CoreFoundation 0x32bd688f __exceptionPreprocess + 163
1 libobjc.A.dylib 0x34b7b259 objc_exception_throw + 33
2 CoreFoundation 0x32bd65c5 -[NSException init] + 1
3 Foundation 0x37296bd7 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 263
...
But if std::exception is thrown, I get only this:
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x34f2632c __pthread_kill + 8
1 libsystem_c.dylib 0x31e4c208 pthread_kill + 48
2 libsystem_c.dylib 0x31e45298 abort + 88
3 libc++abi.dylib 0x33bcaf64 abort_message + 40
4 libc++abi.dylib 0x33bc8346 default_terminate() + 18
5 libobjc.A.dylib 0x349f4368 _objc_terminate + 164
6 libc++abi.dylib 0x33bc83be safe_handler_caller(void (*)()) + 70
7 libc++abi.dylib 0x33bc844a std::terminate() + 14
8 libc++abi.dylib 0x33bc981e __cxa_rethrow + 82
9 libobjc.A.dylib 0x349f42a2 objc_exception_rethrow + 6
10 CoreFoundation 0x329a5506 CFRunLoopRunSpecific + 398
11 CoreFoundation 0x329a5366 CFRunLoopRunInMode + 98
12 GraphicsServices 0x32af2432 GSEventRunModal + 130
13 UIKit 0x34f84cce UIApplicationMain + 1074
14 APP_NAME 0x00086b10 main (main.m:68)
15 APP_NAME 0x00071b98 start + 32
How do I get the exact crash info from this crash log?
Update --
I've given HockeyApp a shot, but it has the same limitation as iTunes crash logs - it doesn't tell me the stack for an unhandled C++ exception.

What you're seeing is an unfortunate quirk of AppKit and UIKit. Both iOS and OS X have an exception handler in CFRunLoop that traps all uncaught exceptions. On OS X, the handler displays the exception to the user with a dialog box, but on iOS, the handler simply rethrows the exception.
Objective-C exceptions, as implemented by NSException, save their backtraces within the exception object right before the actual "throw" happens, as part of [NSException init] (or a similar initializer method). Unfortunately, C++ exceptions don't do the same. Normally, a C++ exception has a backtrace because the runtime library detects that there's no catch and immediately calls std::terminate, which in turn calls abort(), leaving the entire call stack intact, like so:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff93ef8d46 __kill + 10
1 libsystem_c.dylib 0x00007fff89968df0 abort + 177
2 libc++abi.dylib 0x00007fff8beb5a17 abort_message + 257
3 libc++abi.dylib 0x00007fff8beb33c6 default_terminate() + 28
4 libobjc.A.dylib 0x00007fff8a196887 _objc_terminate() + 111
5 libc++abi.dylib 0x00007fff8beb33f5 safe_handler_caller(void (*)()) + 8
6 libc++abi.dylib 0x00007fff8beb3450 std::terminate() + 16
7 libc++abi.dylib 0x00007fff8beb45b7 __cxa_throw + 111
8 test 0x0000000102999f3b main + 75
9 libdyld.dylib 0x00007fff8e4ab7e1 start + 1
However, when the run loop exception handler traps the exception, execution resumes normally within the catch block. The original backtrace is therefore lost. The rethrow subsequently calls std::terminate, but at this point, the call stack reflects the run loop exception handler.
To get a backtrace from a C++ exception in this circumstance, you have to throw an exception object which mimics NSException and reads the call stack as part of its constructor, and make sure that all exceptions thrown in your code do the same. std::exception doesn't do this, and it's not at all likely that any third-party code you're using will either.
File a bug with Apple asking them to remove the CFRunLoop exception handler, or at least provide an API for shutting it off. There is no API, not even an SPI, for doing this right now.

I've had luck with improving mpipe3's answer.
In my main method, I use a try-catch to get the C++ exception and then call a dispatch_sync on dispatch_get_global_queue. Now the full stack trace with line numbers will show on Crashlytics (crash manager).
int main(int argc, char *argv[]) {
#autoreleasepool {
#try{
return UIApplicationMain(argc, argv, nil, #"AppControllerClassName");
} #catch (NSException *exception) {/* Catch any uncaught exceptions and print out a friendly call stack. Instead of an ugly memory addresses. */
NSString * message = [NSString stringWithFormat:#"Uncaught exception %# : %#\n %#", exception.name, exception.reason, [exception callStackSymbols]];
[LogManager e:#"main.m" Message:message Exception: exception];
#throw;
} #catch (...){
//Attempt to get the correct stacktrace for C++ exceptions.
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
#throw;
});
}
return 0;
}
}
This works as it avoids the CFRunLoop exception handler by using GCD to throw the exception.

Following on from Gwynne Raskind answer you can avoid the CFRunLoop exception handler by using GCD to dispatch a call to a block of C++ code synchronously:
namespace
{
void MyThrowingCode()
{
throw std::runtime_error("My Exception");
}
}
- (void)objcHandlerCalledFromARunLoop
{
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
MyThrowingCode();
});
}
You might need to create your own queues rather than using a single shared queue.
The crash log looks like this:
0 libsystem_kernel.dylib 0x3aa39350 __pthread_kill + 8
1 libsystem_c.dylib 0x3a9affb2 pthread_kill + 54
2 libsystem_c.dylib 0x3a9ec366 abort + 90
3 libc++abi.dylib 0x39f94dda abort_message + 70
4 libc++abi.dylib 0x39f92094 default_terminate() + 20
5 libobjc.A.dylib 0x3a545a70 _objc_terminate() + 168
6 libc++abi.dylib 0x39f92118 safe_handler_caller(void (*)()) + 76
7 libc++abi.dylib 0x39f921b0 std::terminate() + 16
8 libc++abi.dylib 0x39f9359a __cxa_throw + 118
9 Test 0x000fddfc MyThrowingCode() (MainViewController.mm:177)
10 Test 0x000fe38c __35-[MainViewController toolsClick:]_block_invoke (MainViewController.mm:184)
11 libdispatch.dylib 0x3a95f5d8 _dispatch_client_callout + 20
12 libdispatch.dylib 0x3a962776 _dispatch_sync_f_invoke + 22
13 Test 0x000fde90 -[MainViewController toolsClick:] (MainViewController.mm:183)
14 UIKit 0x34744082 -[UIApplication sendAction:to:from:forEvent:] + 66
15 UIKit 0x3474410c -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 116
16 UIKit 0x34744082 -[UIApplication sendAction:to:from:forEvent:] + 66
17 UIKit 0x34744036 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 26
18 UIKit 0x34744010 -[UIControl sendAction:to:forEvent:] + 40
19 UIKit 0x347438c6 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 498
20 UIKit 0x34743db4 -[UIControl touchesEnded:withEvent:] + 484
21 UIKit 0x3466c5f4 -[UIWindow _sendTouchesForEvent:] + 520
22 UIKit 0x346598dc -[UIApplication sendEvent:] + 376
23 UIKit 0x346591ea _UIApplicationHandleEvent + 6194
24 GraphicsServices 0x363715f4 _PurpleEventCallback + 588
25 GraphicsServices 0x36371222 PurpleEventCallback + 30
26 CoreFoundation 0x3281f3e4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
27 CoreFoundation 0x3281f386 __CFRunLoopDoSource1 + 134
28 CoreFoundation 0x3281e20a __CFRunLoopRun + 1378
29 CoreFoundation 0x32791238 CFRunLoopRunSpecific + 352
30 CoreFoundation 0x327910c4 CFRunLoopRunInMode + 100
31 GraphicsServices 0x36370336 GSEventRunModal + 70
32 UIKit 0x346ad2b4 UIApplicationMain + 1116
33 Test 0x00120462 main (main.mm:55)
34 libdyld.dylib 0x3a972b1c start + 0

looks like the exception is happening from inside UIApplicationMain()... You could try converting your main.m file to a main.mm file, and doing this:
int main(...)
{
try
{
return UIApplicationMain(...);
}
catch( exception e )
{
cerr < e.what() ;
}
}
I didn't actually try it, however...

Related

SIGABRT crash on __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__

I have a SIGABRT crash log that is unfamiliar to me. Looks like it's throwing an exception, but I can't see where the exception is listed or the root cause of it.
This is running on a customer's iPad 2 / iOS 4.3.
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x33ed3a1c __pthread_kill + 8
1 libsystem_c.dylib 0x354d83b4 pthread_kill + 52
2 libsystem_c.dylib 0x354d0bf8 abort + 72
3 libstdc++.6.dylib 0x33671a64 __gnu_cxx::__verbose_terminate_handler() + 376
4 libobjc.A.dylib 0x3636906c _objc_terminate + 104
5 libstdc++.6.dylib 0x3366fe36 __cxxabiv1::__terminate(void (*)()) + 46
6 libstdc++.6.dylib 0x3366fe8a std::terminate() + 10
7 libstdc++.6.dylib 0x3366ff5a __cxa_throw + 78
8 libobjc.A.dylib 0x36367c84 objc_exception_throw + 64
9 Foundation 0x33f69924 __NSThreadPerformPerform + 648
10 CoreFoundation 0x33e4ba72 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
11 CoreFoundation 0x33e4d758 __CFRunLoopDoSources0 + 376
12 CoreFoundation 0x33e4e4e4 __CFRunLoopRun + 224
13 CoreFoundation 0x33ddeebc CFRunLoopRunSpecific + 224
14 CoreFoundation 0x33ddedc4 CFRunLoopRunInMode + 52
15 GraphicsServices 0x33544418 GSEventRunModal + 108
16 GraphicsServices 0x335444c4 GSEventRun + 56
17 UIKit 0x34416d62 -[UIApplication _run] + 398
18 UIKit 0x34414800 UIApplicationMain + 664
19 MyApp 0x000190c4 main (main.m:14)
20 MyApp 0x0001907c 0x18000 + 4220
Where would I start looking to diagnose this?
The program should print information about the exception to the device console (viewable in the Xcode organizer when the device is connected). It would be very, very helpful to see this information.
_NSThreadPerformPerform is used by the performSelector... family of methods. So look at your use of those methods. In particular, figure out if it's possible that you're asking an object to perform a selector that it doesn't support. That would throw an exception.

Crash on [NSURLConnection releaseDelegate] in a function without NSURLConnections, how do I culprit?

Hullo,
I am experimenting a very vicious crash that shows up in the following way in the device logs:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x50000008
Crashed Thread: 0`
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x33b24c98 objc_msgSend + 16
1 Foundation 0x3429465a _NSURLConnectionReleaseClient + 30
2 CFNetwork 0x355ac608 ClientContextHolder<CFURLConnectionClient_V4>::forget() + 20
3 CFNetwork 0x355ac5ea URLConnectionClient::releaseClientLocked() + 34
4 CFNetwork 0x355a0e9a URLConnectionClient::processEvents() + 170
5 CFNetwork 0x355a0de2 URLConnection::multiplexerClientPerform(RunLoopMultiplexer*) + 30
6 CFNetwork 0x355a0d54 MultiplexerSource::perform() + 120
7 CFNetwork 0x355a0cd2 MultiplexerSource::_perform(void*) + 2
8 CoreFoundation 0x3039ca72 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
9 CoreFoundation 0x3039e758 __CFRunLoopDoSources0 + 376
10 CoreFoundation 0x3039f4e4 __CFRunLoopRun + 224
11 CoreFoundation 0x3032febc CFRunLoopRunSpecific + 224
12 CoreFoundation 0x3032fdc4 CFRunLoopRunInMode + 52
13 GraphicsServices 0x35571418 GSEventRunModal + 108
14 GraphicsServices 0x355714c4 GSEventRun + 56
15 UIKit 0x358c7d62 -[UIApplication _run] + 398
16 UIKit 0x358c5800 UIApplicationMain + 664
17 inArrivo 0x000023ca main (main.m:14)
18 inArrivo 0x00002394 start + 32
After having enabled NSZombie I also have a crash on the compiler log of the following form:
2011-05-09 16:12:24.400 inArrivo[5019:707] * -[NSURLConnection releaseDelegate]: message sent to deallocated instance 0x5d61670
appearing on the app main with the last NSLog comeing from a function with no url connections. Also if I remove some pieces of very innocent code from that function, no crash occurs, and the same happens when I run the complete application on the simulator.
Could someone give me some hints about what I may do to locate the piece of code producing the crash? Normal debugging of course is of little help here.
Thanks,
Fabrizio Bartolomucci
The message indicates that the delegate for NSURLConnection was deallocated. I would suggest you check the delegate object to see if you are doing an extra release on it.

Rejected iPhone app has strange crash logs

My app was rejected from the app store due to a crash that produced the crash log below. What is even more strange than the crash is that the steps given to reproduce it don't happen to me or any of 10+ beta testers (on differing iOS devices). Can anyone help explain this more? I know the exception codes are some sort of memory thing, but is that the only reason that could cause this crash log? For instance, I don't even get a line number.
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Thread 0 Crashed:
0 libSystem.B.dylib 0x33bd52d4 __kill + 8
1 libSystem.B.dylib 0x33bd52c4 kill + 4
2 libSystem.B.dylib 0x33bd52b6 raise + 10
3 libSystem.B.dylib 0x33be9d72 abort + 50
4 libstdc++.6.dylib 0x31bdba20 __gnu_cxx::__verbose_terminate_handler() + 376
5 libobjc.A.dylib 0x3347c594 _objc_terminate + 104
6 libstdc++.6.dylib 0x31bd9df2 __cxxabiv1::__terminate(void (*)()) + 46
7 libstdc++.6.dylib 0x31bd9e46 std::terminate() + 10
8 libstdc++.6.dylib 0x31bd9f16 __cxa_throw + 78
9 libobjc.A.dylib 0x3347b4c4 objc_exception_throw + 64
10 Foundation 0x33639910 __NSThreadPerformPerform + 648
11 CoreFoundation 0x33a767d6 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
12 CoreFoundation 0x33a485b0 __CFRunLoopDoSources0 + 376
13 CoreFoundation 0x33a47e54 __CFRunLoopRun + 224
14 CoreFoundation 0x33a47c80 CFRunLoopRunSpecific + 224
15 CoreFoundation 0x33a47b88 CFRunLoopRunInMode + 52
16 GraphicsServices 0x33b0e4a4 GSEventRunModal + 108
17 GraphicsServices 0x33b0e550 GSEventRun + 56
18 UIKit 0x32099322 -[UIApplication _run] + 406
19 UIKit 0x32096e8c UIApplicationMain + 664
20 AppName 0x00002172 main (main.m:14)
21 AppName 0x0000213c start + 32
Your code threw an un-handled exception somewhere or called abort() for some reason. It looks like it's happening in a dispatch to the main thread (so somewhere you are calling something like [obj performSelectorOnMainThread:#selector(something:) withObject:nil] or something similar. My best guess is that the selector you're choosing doesn't exist on the object (either due to memory management issues, like the object was replaced by something else) or due to some dynamic assignment you're doing.

Application Crashing due to EXC_BAD_ACCESS

Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000000
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x00004420 objc_msgSend + 24
1 CoreFoundation 0x000042a6 CFRetain + 54
2 CoreFoundation 0x0000a9f0 __CFBasicHashStandardRetainValue + 8
3 CoreFoundation 0x000054c0 __CFBasicHashAddValue + 100
4 CoreFoundation 0x00006184 CFBasicHashAddValue + 276
5 CoreFoundation 0x00006cfe CFDictionaryCreate + 58
6 CoreFoundation 0x00033d7c -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 1456
7 CoreFoundation 0x000361bc -[NSDictionary initWithObjectsAndKeys:] + 776
8 iota 0x0000c4cc 0x1000 + 46284
9 iota 0x00009282 0x1000 + 33410
10 iota 0x0000952a 0x1000 + 34090
11 Foundation 0x00015432 _nsnote_callback + 150
12 CoreFoundation 0x000271da __CFXNotificationPost_old + 390
13 CoreFoundation 0x00026e7a _CFXNotificationPostNotification + 122
14 Foundation 0x0000b9f6 -[NSNotificationCenter postNotification:] + 138
15 Foundation 0x0007ae02 postQueueNotifications + 258
16 Foundation 0x0007afae __NSPostIdleQueueNotes + 6
17 CoreFoundation 0x00031084 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 12
18 CoreFoundation 0x00030eb2 __CFRunLoopDoObservers + 494
19 CoreFoundation 0x00028206 __CFRunLoopRun + 934
20 CoreFoundation 0x00027d74 CFRunLoopRunSpecific + 220
21 CoreFoundation 0x00027c82 CFRunLoopRunInMode + 54
22 GraphicsServices 0x00004e84 GSEventRunModal + 188
23 UIKit 0x00004f8c -[UIApplication _run] + 564
24 UIKit 0x000024cc UIApplicationMain + 964
25 iota 0x0000533a 0x1000 + 17210
26 iota 0x000052fc 0x1000 + 17148
NSDictionary *contactNameDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:item, #"contact", sortName, #"contactSortName", compositeName, #"compositeName", nil];
The crashes are random. Like it happens once in 15 trials of a particular action.
KERN_PROTECTION_FAILURE - means that your program is accessing a shared memory that it didn't have access to. That's why kenel sent killed your process. I'm pretty sure that some of your pointers point to wrong location. E.g.
NSObject* obj;
obj would have garbage as it's value. You have to declare it like this:
NSObject* obj = nil;
Without more info, it's hard to say. Usually it's because you try to access/insert into your dictionary an object that doesn't exist anymore.
Check if you're not inserting something that is not an instance of NSObject, like an int or something.
Given that you are using initWithObjectsAndKeys:, make sure that you have nil-terminated the list of arguments, as that's a common mistake that can lead to crashes.

Getting strange intermittent "unrecognized selector" exceptions in iPhone app

Recently, I've been getting intermittent error reports from my app claiming "unrecognized selector" in areas that could not possibly cause them, and yet they do.
For example, this one:
Error: NSInvalidArgumentException: *** -[NSCFString didReceiveMemoryWarning]: unrecognized selector sent to instance 0x541fe0
0 CoreFoundation 0x32de1e23 __handleUncaughtException + 230
1 libobjc.A.dylib 0x3266d894 _objc_terminate + 156
2 libstdc++.6.dylib 0x338c3a8c _ZN10__cxxabiv111__terminateEPFvvE + 84
3 libstdc++.6.dylib 0x338c3b04 _ZSt9terminatev + 24
4 libstdc++.6.dylib 0x338c3c2c __cxa_throw + 108
5 libobjc.A.dylib 0x3266be5c objc_exception_throw + 112
6 CoreFoundation 0x32de2bfd -[NSObject doesNotRecognizeSelector:] + 112
7 CoreFoundation 0x32d67b19 ___forwarding___ + 480
8 CoreFoundation 0x32d5e840 _CF_forwarding_prep_0 + 48
9 Foundation 0x33f765d9 _nsnote_callback + 184
10 CoreFoundation 0x32d9e511 _CFXNotificationPostNotification + 304
11 Foundation 0x33f741b3 -[NSNotificationCenter postNotificationName:object:userInfo:] + 70
12 Foundation 0x33f76519 -[NSNotificationCenter postNotificationName:object:] + 20
13 UIKit 0x30d18db8 -[UIApplication _performMemoryWarning] + 68
14 UIKit 0x30d18d50 -[UIApplication _receivedMemoryNotification] + 136
15 UIKit 0x30d18c80 _memoryStatusChanged + 64
16 CoreFoundation 0x32d66eb7 __CFNotificationCenterDarwinCallBack + 26
17 CoreFoundation 0x32d5cb51 __CFMachPortPerform + 78
18 CoreFoundation 0x32da452b CFRunLoopRunSpecific + 2302
19 CoreFoundation 0x32da3c1f CFRunLoopRunInMode + 50
20 GraphicsServices 0x31bb9374 GSEventRunModal + 196
21 UIKit 0x30bf3c30 -[UIApplication _run] + 560
22 UIKit 0x30bf2230 UIApplicationMain + 968
23 Mind 0x00002c68 main + 72
24 Mind 0x00002be4 start + 52
This is the OS sending a memory warning to my app, and somehow the application class has changed into a string.
It seems to happen a lot more when the code is invoked via an NSOperation:
Error: NSInvalidArgumentException: -[NSCFString setObject:forKey:]: unrecognized selector sent to instance 0x3e793088
9 Mind 0x0015de70 -[CCTextureCache textureFromFile:] + 528
10 Mind 0x0015d9f4 -[CCTextureCache loadImageUncached:pixelFormat:] + 116
11 Mind 0x0015d058 -[CCTextureCache addImage:pixelFormat:] + 152
12 Mind 0x00080524 -[ImageLoader imageWithFile:pixelFormat:] + 84
13 Mind 0x000854c4 -[ImageLoadOperation performLoad] + 68
14 Mind 0x00085800 -[ResourceLoadOperation main] + 112
15 Foundation 0x30c4c8b5 -[__NSOperationInternal start] + 664
16 Foundation 0x30c4c613 -[NSOperation start] + 22
17 Foundation 0x30cbdb63 ____startOperations_block_invoke_2 + 46
18 libSystem.B.dylib 0x31227858 _dispatch_call_block_and_release + 20
19 libSystem.B.dylib 0x3122863c _dispatch_worker_thread2 + 128
20 libSystem.B.dylib 0x311b1544 _pthread_wqthread + 400
21 libSystem.B.dylib 0x311a8b74 __stack_chk_fail + 4294967295
The code in question is:
[textures setObject:texture forKey:filename];
textures is type NSMutableDictionary* and never gets reassigned or deallocated (naturally, since this is a cache object). This is the only place where setObject is invoked in this method, yet according to the stack trace, textures was a string.
I also get this weirdness:
Error: NSInvalidArgumentException: -[NSConcreteNotification getPixelFormatForIdentifier:]: unrecognized selector sent to instance 0x5c021b0
9 Mind 0x0015dd0c -[CCTextureCache textureFromFile:] + 172
10 Mind 0x0015d9f4 -[CCTextureCache loadImageUncached:pixelFormat:] + 116
11 Mind 0x0015d058 -[CCTextureCache addImage:pixelFormat:] + 152
12 Mind 0x00080524 -[ImageLoader imageWithFile:pixelFormat:] + 84
13 Mind 0x000854c4 -[ImageLoadOperation performLoad] + 68
14 Mind 0x00085800 -[ResourceLoadOperation main] + 112
15 Foundation 0x347b78b5 -[__NSOperationInternal start] + 664
16 Foundation 0x347b7613 -[NSOperation start] + 22
17 Foundation 0x34828b63 ____startOperations_block_invoke_2 + 46
18 libSystem.B.dylib 0x32a2f858 _dispatch_call_block_and_release + 20
19 libSystem.B.dylib 0x32a3063c _dispatch_worker_thread2 + 128
20 libSystem.B.dylib 0x329b9544 _pthread_wqthread + 400
21 libSystem.B.dylib 0x329b0b74 __stack_chk_fail + 4294967295
This trace is from the following code in CCTextureCache:
CCTexture2DPixelFormat pixelFormat = [self getPixelFormatForIdentifier:identifier];
How CCTextureCache changed into NSConcreteNotification after having already called a number of methods on itself is baffling to say the least.
Has anyone else noticed this sort of thing? Am I somehow getting memory corruption?
Did you check some race conditions about multi-threads ? It seems like some resource freed by another thread, and current thread send a messaged to a deallocated object.
Error: NSInvalidArgumentException: -[NSCFString setObject:forKey:]: unrecognized selector sent to instance 0x3e793088
9 Mind 0x0015de70 -[CCTextureCache textureFromFile:] + 528
10 Mind 0x0015d9f4 -[CCTextureCache loadImageUncached:pixelFormat:] + 116
11 Mind 0x0015d058 -[CCTextureCache addImage:pixelFormat:] + 152
12 Mind 0x00080524 -[ImageLoader imageWithFile:pixelFormat:] + 84
13 Mind 0x000854c4 -[ImageLoadOperation performLoad] + 68
14 Mind 0x00085800 -[ResourceLoadOperation main] + 112
15 Foundation 0x30c4c8b5 -[__NSOperationInternal start] + 664
16 Foundation 0x30c4c613 -[NSOperation start] + 22
17 Foundation 0x30cbdb63 ____startOperations_block_invoke_2 + 46
18 libSystem.B.dylib 0x31227858 _dispatch_call_block_and_release + 20
19 libSystem.B.dylib 0x3122863c _dispatch_worker_thread2 + 128
20 libSystem.B.dylib 0x311b1544 _pthread_wqthread + 400
21 libSystem.B.dylib 0x311a8b74 __stack_chk_fail + 4294967295
This is often caused by memory management errors. Did you try zombies?
...with zombies enabled, messages to deallocated objects will no longer behave
strangely or crash in difficult-to-understand ways, but will instead log a message
and die in a predictable and debugger-breakpointable way. This is the tool to use
when trying to track down over-releases and premature releases.
I just ran into the same problem, but it turns out I had made a stupid mistake:
I had declared a member like this in the header file:
NSMutableDictionary* myDict;
But then initialized it like this in the .m file:
myDict = [[NSDictionary alloc] init];
which is valid and all, because the NSMutableDictionary is derived from the NSDictionary class. Therefore all calls that are inherited from NSDictionary actually worked, but the calls specific to NSMutableDictionary [setObject: forKey:] failed because I tried to invoke them on the parent class.
The mistake was really dumb, but I was also thrown off by the fact that the debugger reported the type of myDict as something totally different (neither NSDictionary, nor NSMutableDictionary). I hope this helps some other tired coder :-)