When posting notifications with NSNotificationCenter, is there any reason why passing in a NSMutableDictionary instead of an NSDictionary as the userInfo could cause a crash?
- (void)postNotificationName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo;
I'm seeing the following crash log:
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0xffffffffe0000008
0 libobjc.A.dylib 0x31516fbc objc_msgSend + 16
1 Foundation 0x3195b50f __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 19
2 CoreFoundation 0x37a02577 ___CFXNotificationPost_block_invoke_0 + 71
3 CoreFoundation 0x3798e0cf _CFXNotificationPost + 1407
4 Foundation 0x318cf3fb -[NSNotificationCenter postNotificationName:object:userInfo:] + 67
It seems that your observer is crashing the app. Did you remove it from observer list before dealloc ?
Related
I am using AdWhirl in my iphone app and I am displaying the adView in several different views. Each view has a different adView ivar. Problem is that when I am switching the views quickly, ASIHttpRequest within Adwhirl code tries to call the view after the view has been deallocted. I have tried setting the delegate to nil in my view but to no avail. Are there any other workarounds to cancel the AdWhirl ASIHttpRequest when the view is deallocated. In my view dealloc I am doing something like:
adView.delegate = nil;
adView = nil
where adView is an ivar declared like:
#property (nonatomic, retain) AdWhirlView *adView;
Crash Log:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000c
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x32ad5c98 objc_msgSend + 16
1 SocialMashup 0x0005503c -[ASIHTTPRequest requestReceivedResponseHeaders:] (ASIHTTPRequest.m:1954)
2 CoreFoundation 0x36387efc -[NSObject(NSObject) performSelector:withObject:] + 16
3 Foundation 0x32cfe7a2 __NSThreadPerformPerform + 262
4 CoreFoundation 0x363f1a72 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
5 CoreFoundation 0x363f3758 __CFRunLoopDoSources0 + 376
6 CoreFoundation 0x363f44e4 __CFRunLoopRun + 224
7 CoreFoundation 0x36384ebc CFRunLoopRunSpecific + 224
8 CoreFoundation 0x36384dc4 CFRunLoopRunInMode + 52
9 GraphicsServices 0x30cdd418 GSEventRunModal + 108
10 GraphicsServices 0x30cdd4c4 GSEventRun + 56
11 UIKit 0x3037cd62 -[UIApplication _run] + 398
12 UIKit 0x3037a800 UIApplicationMain + 664
13 ZFirewall.dylib 0x013dcb24 0x13cd000 + 64292
14 SocialMashup 0x000024ae main (main.m:17)
15 SocialMashup 0x00002444 start + 32
I'm pretty sure AdWhirl doesn't use ASIHTTPRequest at all. Maybe a particular ad network you're using does, but the logs don't even seem to point to AdWhirl as the culprit.
when I call API and parse response xml, sometime I got this error ..
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSXMLParser stringByAppendingString:]: unrecognized selector sent to instance 0x6a22080'
*** Call stack at first throw:
(
0 CoreFoundation 0x014c7be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x012bc5c2 objc_exception_throw + 47
2 CoreFoundation 0x014c96fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x01439366 ___forwarding___ + 966
4 CoreFoundation 0x01438f22 _CF_forwarding_prep_0 + 50
5 CityDeal24 0x0002520e -[CategoryXmlHandler parser:foundCharacters:] + 112
6 Foundation 0x001e8dd4 _characters + 235
7 libxml2.2.dylib 0x018371fb xmlParseCharData + 287
8 libxml2.2.dylib 0x01845a6f xmlParseChunk + 3730
9 Foundation 0x001e921a -[NSXMLParser parse] + 321
10 CityDeal24 0x00025030 -[CategoryXmlHandler parseXML:apiUrl:] + 444
11 CityDeal24 0x00004ac6 -[DagenDealsViewController downloadCategories] + 227
12 CityDeal24 0x00006708 -[DagenDealsViewController doInBackgroundWhenViewWillLoad] + 114
13 Foundation 0x0011ad4c -[NSThread main] + 81
14 Foundation 0x0011acd8 __NSThread__main__ + 1387
15 libSystem.B.dylib 0x9821c85d _pthread_start + 345
16 libSystem.B.dylib 0x9821c6e2 thread_start + 34
)
terminate called after throwing an instance of 'NSException'
Please check that, all the string data have values or not.
If some string value will be nil then you will get such error. So, include the condition for null value also.
As the error says, you are calling stringByAppendingString: on an NSXMLParser. Search your project for stringByAppendingString: and make sure you are calling it on a string.
Look like, you are calling stringByAppendingString method on the object of NSXMLParser.
EDITED:
I assume, you have declared currentElement in your .h as NSMutableArray and alloced that in init function like below.
currentElement = [NSMutableArray alloc] initWithCapacity:10];
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
[currentElement appendString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
NSLog(#"%#",string);
}
New here (this forum and Xcode in general), so bear with me.
I've spent multiple hours off and on over the last severals days trying to track down what exactly that I'm doing wrong here, but I just don't seem to be able to pinpoint my issue.
Here's the relevant sections of my code (I believe).
In the header:
#interface BlahViewController : UIViewController {
NSMutableString *display;
}
#property (nonatomic, retain) NSMutableString *display;
In the main:
#implementation BlahViewController
#synthesize display;
- (void)viewDidLoad {
self.display = [[NSMutableString alloc] init];
}
- (void)anotherFunction:(UIButton *)sender {
NSString *info = [[sender titleLabel] text];
[self.display appendString:info];
}
I run the code, press the UIButton, and I get an error. Here's the initial throw:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM appendString:]: unrecognized selector sent to instance 0x4e3d300' ***
Thanks!
EDIT: The whole stack trace was requested, so here it is (after reviewing the stack I realize there may be confusion, I'm writing a very basic calculator currently, so the ViewController, etc, should consider that backdrop and "anotherFunction" = "digitPressed" in this particular case):
* Call stack at first throw:
(
0 CoreFoundation 0x00e345a9 exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f88313 objc_exception_throw + 44
2 CoreFoundation 0x00e360bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00da5966 __forwarding + 966
4 CoreFoundation 0x00da5522 _CF_forwarding_prep_0 + 50
5 Calculator 0x0000273b -[CalculatorViewController digitPressed:] + 113
6 UIKit 0x002bb4fd -[UIApplication sendAction:to:from:forEvent:] + 119
7 UIKit 0x0034b799 -[UIControl sendAction:to:forEvent:] + 67
8 UIKit 0x0034dc2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
9 UIKit 0x0034c7d8 -[UIControl touchesEnded:withEvent:] + 458
10 UIKit 0x002dfded -[UIWindow _sendTouchesForEvent:] + 567
11 UIKit 0x002c0c37 -[UIApplication sendEvent:] + 447
12 UIKit 0x002c5f2e _UIApplicationHandleEvent + 7576
13 GraphicsServices 0x01723992 PurpleEventCallback + 1550
14 CoreFoundation 0x00e15944 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52
15 CoreFoundation 0x00d75cf7 __CFRunLoopDoSource1 + 215
16 CoreFoundation 0x00d72f83 __CFRunLoopRun + 979
17 CoreFoundation 0x00d72840 CFRunLoopRunSpecific + 208
18 CoreFoundation 0x00d72761 CFRunLoopRunInMode + 97
19 GraphicsServices 0x017221c4 GSEventRunModal + 217
20 GraphicsServices 0x01722289 GSEventRun + 115
21 UIKit 0x002c9c93 UIApplicationMain + 1160
22 Calculator 0x00002254 main + 102
23 Calculator 0x000021e5 start + 53
)
terminate called after throwing an instance of 'NSException'
Current language: auto; currently objective-c
* Terminating app due to uncaught
exception
'NSInvalidArgumentException', reason:
'-[__NSArrayM appendString:]:
unrecognized selector sent to instance
0x4e3d300' *
This indicates that you are calling appendString: an instance of some kind of NSArray, which obviously won't work.
Assuming that [self.display appendString:info]; is the actual source of the exception, then it is happening because self.display has likely been over-released and, coincidentally, an NSArray instance was allocated at the same place in memory.
You could use zombie detection to debug this.
Alternatively, you might be corrupting memory somewhere. Or, maybe, there is another assignment to display.
In any case, whenever you have a crash, there will be a backtrace. Please post it. There is the off chance that the crash is happening somewhere else.
5 Calculator 0x0000273b -[CalculatorViewController digitPressed:] + 113
Show the source to your digitPressed: method.
self.display = [[NSMutableString alloc] init];
That is a memory leak; it'll be retained twice. Just do self.display = [NSMutableString string]; and self.display = nil; (in your viewDidUnload).
But that isn't the source of your problem; something is resetting the display variable or it is being over-released. Show all uses of display.
Trouble code:
NSDictionary *contactNameDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:item, #"contact", sortName, #"contactSortName", compositeName, #"compositeName", nil];
Error:
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 0x0000cb04 -[CorpDirViewController reloadDisplayList] (CorpDirViewController.m:833)
Perhaps one (or more) of item, sortName or compositeName have gone out of scope and been garbage collected, even though they're non-nil.
item, sortName or compositeName is nil
I've got an app that throws out the GKSession and makes a new one under various conditions (connection timeout, session fails, etc.). I'm getting memory leaks, though, and it sometimes crashes after a few loops through the reconnect.
Here's my code:
- (void) netConnect:(id) sender {
NSLog(#"allocating GKSession");
currentSession = [[GKSession alloc] initWithSessionID:nil displayName:nil sessionMode:GKSessionModePeer];
currentSession.delegate = self;
currentSession.available = YES;
currentSession.disconnectTimeout = 0;
[currentSession setDataReceiveHandler: self withContext:nil];
}
- (void) netDisconnect:(id) sender {
NSLog(#"DISCONNECTING BY REQUEST");
[currentSession disconnectFromAllPeers];
[currentSession setAvailable:NO];
[currentSession setDelegate:nil];
[currentSession setDataReceiveHandler:nil withContext:nil];
[currentSession release];
currentSession = nil;
}
There's a timer that waits for a successful connection; if it doesn't get one, netDisconnect is called, followed by netConnect again after a 5-second NSTimer delay.
I'm getting leaked GKList, GKTable, and GKAutoPeerIDTable objects, and crashes like this (always occurs after the alloc) :
Date/Time: 2010-09-05 09:35:59.426 -0700
OS Version: iPhone OS 4.0.2 (8A400)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000a
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x0000286c objc_msgSend + 16
1 CoreFoundation 0x000756ea __CFCopyFormattingDescription + 174
2 CoreFoundation 0x00081c8e __CFStringAppendFormatCore + 8666
3 CoreFoundation 0x000146ac _CFStringCreateWithFormatAndArgumentsAux + 64
4 CoreFoundation 0x00014660 CFStringCreateWithFormatAndArguments + 16
5 CoreFoundation 0x0001463c CFStringCreateWithFormat + 16
6 SystemConfiguration 0x00003272 SCDynamicStoreCreateWithOptions + 62
7 SystemConfiguration 0x000033d0 SCDynamicStoreCreate + 12
8 GameKitServices 0x000020ce gckRegisterForNetworkChanges + 154
9 GameKitServices 0x000035c0 GCKSessionCreate + 788
10 GameKitServices 0x00035e7a -[GKSessionInternal initWithSessionID:displayName:session:sessionMode:] + 274
11 GameKit 0x0000fda8 -[GKSession initWithSessionID:displayName:sessionMode:] + 76
Here's another one:
Sun Sep 5 10:28:52 thinner someapp[424] <Warning>: allocating GKSession
Sun Sep 5 10:28:52 thinner someapp[424] <Error>: -[__NSCFData UTF8String]: unrecognized selector sent to instance 0x10a710
Sun Sep 5 10:28:52 thinner someapp[424] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData UTF8String]: unrecognized selector sent to instance 0x10a710'
*** Call stack at first throw:
(
0 CoreFoundation 0x31a9ffd3 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x3428a8a5 objc_exception_throw + 24
2 CoreFoundation 0x31aa3a77 -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
3 CoreFoundation 0x31aa2f15 ___forwarding___ + 508
4 CoreFoundation 0x31a35680 _CF_forwarding_prep_0 + 48
5 GameKitServices 0x327aff13 -[GKSessionInternal initWithSessionID:displayName:session:sessionMode:] + 426
6 GameKit 0x31c15daf -[GKSession initWithSessionID:displayName:sessionMode:] + 82
7 someapp 0x0000584b -[MainViewController netConnect:] + 126
Questions:
• Is this the right way to release and re-allocate GKSessions?
• Should I not be tearing down and re-allocating GKSessions between connections to begin with?
This is a known issue. The workaround is to not pass in nil for the sessionID:
[[GKSession alloc] initWithSessionID:#"com.put.something.here" displayName:nil sessionMode:GKSessionModePeer];