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];
Related
I wanted to confirm that the following functionality is supported:
I have a simple app where I am trying to send an array of strings to UIActivityViewController. The array contains an attributed string and also a regular string. When I click on the share button and open the Mail app, I get a crash and error. However when I only send the attributed string by itself, it works.
I have tried this on IOS6 and it works fine on that.
Here is the configuration:
NSAttributedString *appName=[[NSAttributedString alloc] initWithString:#"TasteBank\n"
attributes:#{NSFontAttributeName : [UIFont boldSystemFontOfSize:[UIFont
systemFontSize]],NSForegroundColorAttributeName:[UIColor brownColor]}];
//crash seen when #"test" added to array without that no crash when mail app opened on ios7
NSMutableArray *dataToShare = [[NSMutableArray alloc ] initWithObjects: appName, #"test", nil];
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:^{}];
IS there something wrong with this? Is this configuration supported in IOS7? if so, could this be a bug?
I see the following error when I run on my iPhone 4 with IOS 7:
2013-10-17 11:43:50.609 testing12[2499:60b] -[NSConcreteMutableAttributedString appendString:]: unrecognized selector sent to instance 0x165ae670
2013-10-17 11:43:50.612 testing12[2499:60b] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableAttributedString appendString:]: unrecognized selector sent to instance 0x165ae670'
First throw call stack:
(0x2ff53f53 0x3a32c6af 0x2ff578e7 0x2ff561d3 0x2fea5598 0x32c389a1 0x328e2f2b 0x328e2bb1 0x328e2791 0x328e23b7 0x328e20dd 0x3284c101 0x3284c101 0x326f9601 0x326f468d 0x326c9a25 0x326c8221 0x2ff1f18b 0x2ff1e65b 0x2ff1ce4f 0x2fe87ce7 0x2fe87acb 0x34ba8283 0x32729a41 0xbd1ed 0x3a834ab7)
I see this error when run on IOS7.0 simulator in XCODE 5:
2013-10-17 11:23:42.054 testing12[3258:a0b] -[NSConcreteMutableAttributedString appendString:]: unrecognized selector sent to instance 0xa181470
2013-10-17 11:23:42.085 testing12[3258:a0b] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableAttributedString appendString:]: unrecognized selector sent to instance 0xa181470'
First throw call stack:
(0 CoreFoundation 0x017345e4 exceptionPreprocess + 180
1 libobjc.A.dylib 0x014b78b6 objc_exception_throw + 44
2 CoreFoundation 0x017d1903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0172490b forwarding___ + 1019
4 CoreFoundation 0x017244ee _CF_forwarding_prep_0 + 14
5 UIKit 0x008bdfa3 -[UIMailActivity prepareWithActivityItems:] + 2346
6 UIKit 0x008b9242 -[UIActivityViewController _executeActivity] + 424
7 UIKit 0x008ba824 -[UIActivityViewController _performActivity:] + 1359
8 libobjc.A.dylib 0x014c981f -[NSObject performSelector:withObject:] + 70
9 UIKit 0x0063c75a -[UIActivityGroupViewController collectionView:didSelectItemAtIndexPath:] + 148
10 UIKit 0x0083929b -[UICollectionView _selectItemAtIndexPath:animated:scrollPosition:notifyDelegate:] + 605
11 UIKit 0x008516d8 -[UICollectionView _userSelectItemAtIndexPath:] + 189
12 UIKit 0x00851895 -[UICollectionView touchesEnded:withEvent:] + 437
13 libobjc.A.dylib 0x014c9874 -[NSObject performSelector:withObject:withObject:] + 77
14 UIKit 0x00382f92 forwardTouchMethod + 271
15 UIKit 0x00383002 -[UIResponder touchesEnded:withEvent:] + 30
16 libobjc.A.dylib 0x014c9874 -[NSObject performSelector:withObject:withObject:] + 77
17 UIKit 0x00382f92 forwardTouchMethod + 271
18 UIKit 0x00383002 -[UIResponder touchesEnded:withEvent:] + 30
19 UIKit 0x0059dd7f _UIGestureRecognizerUpdate + 7166
20 UIKit 0x00268d4a -[UIWindow _sendGesturesForEvent:] + 1291
21 UIKit 0x00269c6a -[UIWindow sendEvent:] + 1030
22 UIKit 0x0023da36 -[UIApplication sendEvent:] + 242
23 UIKit 0x00227d9f _UIApplicationHandleEventQueue + 11421
24 CoreFoundation 0x016bd8af CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
25 CoreFoundation 0x016bd23b __CFRunLoopDoSources0 + 235
26 CoreFoundation 0x016da30e __CFRunLoopRun + 910
27 CoreFoundation 0x016d9b33 CFRunLoopRunSpecific + 467
28 CoreFoundation 0x016d994b CFRunLoopRunInMode + 123
29 GraphicsServices 0x036859d7 GSEventRunModal + 192
30 GraphicsServices 0x036857fe GSEventRun + 104
31 UIKit 0x0022a94b UIApplicationMain + 1225
32 testing12 0x00002efd main + 141
33 libdyld.dylib 0x01d70725 start + 0
34 ??? 0x00000001 0x0 + 1
)
I don't know if this will help but I fixed my problem with a custom activity provider that just gave a NSString to email types and the attributed string to all the others. The email controller autodetected that the string was HTML and formatted it correctly anyway.
I guess if you can get the same effect from HTML that you can with your attributed string this might help?
#implementation ProductActivityItemProvider
...
- (id)placeholderItem {
return [[NSAttributedString alloc] initWithString:#""];
}
- (NSString *)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(NSString *)activityType {
if ([activityType isEqualToString:UIActivityTypeMail])
return [NSString stringWithFormat:#"I shared %#", self.product.title];
return nil;
}
- (id)item {
NSString *raw = [NSString stringWithFormat:#"<html><body>%#<br />%#<br /><b>%#</b></body></html>",
self.product.designer,
self.product.title,
self.product.price];
// The mail controller will (a) autodetect HTML and (b) crash if it's given an attributed string. sigh.
if ([self.activityType isEqualToString:UIActivityTypeMail])
return raw;
NSData *data = [raw dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *options = #{
NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute : #(NSUTF8StringEncoding)
};
NSAttributedString *text = [[NSAttributedString alloc] initWithData:data
options:options
documentAttributes:nil
error:nil];
return text;
}
#end
Got some fast solution here. Just implement a category:
#implementation NSMutableAttributedString (append)
-(void)appendString:(id)string{
if([string isKindOfClass:[NSString class]]){
[self appendAttributedString:[[NSAttributedString alloc] initWithString:string]];
}else if ([string isKindOfClass:[NSAttributedString class]]){
[self appendAttributedString:string];
}
}
#end
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 ?
I am using UIImagePickerController to load saved photo from iphone library.
but when I scroll images up or down my application crashing..
I get following error:
2011-04-21 14:26:33.357 Exchange[72452:5803] Running conversion tracker in a background thread.
2011-04-21 14:26:40.449 Exchange[72452:207] upload from gallery event here
2011-04-21 14:26:42.277 Exchange[72452:207] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x6dc35a0> was mutated while being enumerated.(
"<PLImageTableSegment: 0x6937f80>",
"<null>",
"<null>",
"<null>",
"<null>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>"
)'
*** Call stack at first throw:
(
0 CoreFoundation 0x015645a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x016b8313 objc_exception_throw + 44
2 CoreFoundation 0x01564069 __NSFastEnumerationMutationHandler + 377
3 CoreFoundation 0x0155d838 -[__NSArrayM dealloc] + 152
4 PhotoLibrary 0x0608d696 +[PLImageTable releaseSegmentCache] + 37
5 PhotoLibrary 0x0606cf5a -[PLPhotoLibrary dealloc] + 183
6 CoreFoundation 0x0147b04c CFRelease + 92
7 CoreFoundation 0x014a018d _CFAutoreleasePoolPop + 237
8 Foundation 0x000e33eb -[NSAutoreleasePool release] + 167
9 UIKit 0x003943ee _UIApplicationHandleEvent + 8792
10 GraphicsServices 0x01d9c992 PurpleEventCallback + 1550
11 CoreFoundation 0x01545944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
12 CoreFoundation 0x014a5cf7 __CFRunLoopDoSource1 + 215
13 CoreFoundation 0x014a2f83 __CFRunLoopRun + 979
14 CoreFoundation 0x014a2840 CFRunLoopRunSpecific + 208
15 CoreFoundation 0x014a2761 CFRunLoopRunInMode + 97
16 GraphicsServices 0x01d9b1c4 GSEventRunModal + 217
17 GraphicsServices 0x01d9b289 GSEventRun + 115
18 UIKit 0x00397c93 UIApplicationMain + 1160
19 ArmaniExchange 0x000022a4 main + 102
20 ArmaniExchange 0x00002235 start + 53
21 ??? 0x00000001 0x0 + 1
)
terminate c
alled after throwing an instance of 'NSException'
Thanks in advance.
I had the same problem. I tried he first answer here : UIImagePickerController crashes on rapid scrolling, slower than photos app
replacing
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
by
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
It works like a charm now.
Open the releaseSegmentCache method of PLImageTable. You will find code similar to this:
for (id object in array) {
// do something with object
if ([object meetsCondition:#"Foo"]) {
[array removeObject:object];
}
}
But you are not allowed to change arrays when you are enumerating them. So you have to find another solution. You could save all objects that should be removed in another array, and then delete all those when you are done enumerating. Like this for example:
NSMutableArray *objectsToDelete = [NSMutableArray array];
for (id object in array) {
// do something with object
if ([object meetsCondition:#"Foo"]) {
[objectsToDelete addObject:object];
}
}
[array removeObjectsInArray:objectsToDelete];
Look for a for loop that adds or removes objects from whatever it is iterating through. Probably in [PLImageTable releaseSegmentCache]. For example:
for (NSString *string in stringsArray) {
[stringsArray removeObject:string];
}
I have set a timer to reset an attribute of an object :
- (IBAction)open:(id)sender {
int viewID = ((UIButton*)sender).tag;
for (int i=0; i<[self.webViews count]; i++) {
WebViewController* page = [self.webViews objectAtIndex:i];
if (page.loadFinished == NO) {
[page.webView stopLoading];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(setLoadingNotFinished:) userInfo:page repeats:NO];
}
}
- (void) setLoadingNotFinished:(WebViewController*)page {
page.loadFinished = NO;
}
When entering the setLoadingNotFinished method, I have this crash :
2011-04-25 04:34:22.358 MyApp[7823:207] -[__NSCFTimer setLoadFinished:]: unrecognized selector sent to instance 0x4b203d0
2011-04-25 04:34:22.360 MyApp[7823:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFTimer setLoadFinished:]: unrecognized selector sent to instance 0x4b203d0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dca5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f1e313 objc_exception_throw + 44
2 CoreFoundation 0x00dcc0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d3b966 ___forwarding___ + 966
4 CoreFoundation 0x00d3b522 _CF_forwarding_prep_0 + 50
5 MyApp 0x00003a42 -[MainGridController setLoadingNotFinished:] + 66
6 Foundation 0x007ba749 __NSFireTimer + 125
7 CoreFoundation 0x00dab8c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
8 CoreFoundation 0x00dace74 __CFRunLoopDoTimer + 1220
9 CoreFoundation 0x00d092c9 __CFRunLoopRun + 1817
10 CoreFoundation 0x00d08840 CFRunLoopRunSpecific + 208
11 CoreFoundation 0x00d08761 CFRunLoopRunInMode + 97
12 GraphicsServices 0x010021c4 GSEventRunModal + 217
13 GraphicsServices 0x01002289 GSEventRun + 115
14 UIKit 0x0002ac93 UIApplicationMain + 1160
15 MyApp 0x000027e9 main + 121
16 MyApp 0x00002765 start + 53
)
terminate called after throwing an instance of 'NSException'
Why does this crash happens ?
I don't understand why it doesn't find the selector.
The loadFinished attribute is set, even the first test on this attribute works before calling the NSTimer method, and I use this attribute in many places.
page is not nil in the timed method.
The self.webViews is a retained NSMutableArray.
Please check out the code again. I corrected it. It had a syntax error.
The following should fix it:
- (void) setLoadingNotFinished:(NSTimer *)myTimer {
WebViewController *page = (WebViewController *)[myTimer userInfo];
page.loadFinished = NO;
}
The selector method receives the NSTimer as its argument, not the userInfo. Then, with the NSTimer you retrieve the object you previously set as the userInfo.
(In your original -setLoadingNotFinished, page was not the WebViewController, it was the NSTimer. And, setLoadFinished was being sent to the NSTimer, which did not recognize it.)
Note that the error message was telling you that the selector method was being sent to an object of class _NSCFTimer. That gives you a clue as to the nature of the error.
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