So some of my users are getting crashes, and I think iv'e tracked it down to the NSWorkspaceDidTerminateApplicationNotification, I can't reproduce the crash at all so I'm not sure where to go?
here is the generated crash log, maybe I'm missing something obvious:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000010
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Application Specific Information:
objc_msgSend() selector name: invalidate
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x00007fff816f211c objc_msgSend + 40
1 com.apple.Foundation 0x00007fff87ef58ea _nsnote_callback + 167
2 com.apple.CoreFoundation 0x00007fff869b3000 __CFXNotificationPost + 1008
3 com.apple.CoreFoundation 0x00007fff8699f578 _CFXNotificationPostNotification + 200
4 com.apple.Foundation 0x00007fff87eec84e -[NSNotificationCenter postNotificationName:object:userInfo:] + 101
5 com.apple.AppKit 0x00007fff878efb58 applicationStatusSubsystemCallback + 593
6 com.apple.LaunchServices 0x00007fff83523e6c LSScheduleNotificationReceiveMessageCallbackFunc(__CFMachPort*, void*, long, void*) + 184
7 com.apple.CoreFoundation 0x00007fff869cf68e __CFMachPortPerform + 366
8 com.apple.CoreFoundation 0x00007fff869a76e1 __CFRunLoopRun + 5201
9 com.apple.CoreFoundation 0x00007fff869a5dbf CFRunLoopRunSpecific + 575
10 com.apple.HIToolbox 0x00007fff80ef07ee RunCurrentEventLoopInMode + 333
11 com.apple.HIToolbox 0x00007fff80ef05f3 ReceiveNextEventCommon + 310
12 com.apple.HIToolbox 0x00007fff80ef04ac BlockUntilNextEventMatchingListInMode + 59
13 com.apple.AppKit 0x00007fff87232e64 _DPSNextEvent + 718
14 com.apple.AppKit 0x00007fff872327a9 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155
15 com.apple.AppKit 0x00007fff871f848b -[NSApplication run] + 395
16 com.apple.AppKit 0x00007fff871f11a8 NSApplicationMain + 364
and here is the relevant code:
NSNotificationCenter *center = [[NSWorkspace sharedWorkspace] notificationCenter];
[center addObserver:self selector:#selector(appTerminated:) name:NSWorkspaceDidTerminateApplicationNotification object:nil];
- (void)appTerminated:(NSNotification *)note
{
NSString *app = [NSString stringWithFormat:#"%#", [[note userInfo] objectForKey:#"NSApplicationName"]];
if ([app isEqualToString:Somestring])
{
//do something here
}
}
}
If anyone could give me some pointers as to where to look, i'd be eternally grateful, I've been tearing my hair out for days now...
It looks like your window controller is getting deallocated while still being registered with the notification centre. You need to make sure the window controller is unregistered before deallocation. Otherwise, the notification centre will try to post a notification to a deallocated object, which can trigger an EXC_BAD_ACCESS exception.
For instance, in your window controller implementation:
- (void)dealloc {
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
[super dealloc];
}
This will unregister the window controller with regard to every notification it’s registered with the notification centre.
Looks like a notification fired and tried to call an invalidate method on an object that has been deallocated. Turn on NSZombies and try again.
Related
Inside an instance method I'm calling the same selector on the superclass and getting EXC_BAD_ACCESS. I'm using manual reference counting (not ARC), and this is happening in the main thread. Static analysis reports no issues, not that I take that to mean a clean bill of health. The relevant code is as follows:
CommentListMedia.m (stack frame 1 in the trace below):
- (void)play {
if ((comments.isLoading) && (! comments.isLoaded))
playWhenLoaded = YES;
else [super play]; // <-- EXC_BAD_ACCESS happens here
}
MediaControls.m (stack frame 2 in the trace below):
- (void)play {
[media play]; // <-- this calls the code above
[self notifyWithName:MediaControlsDidPlayNotification];
}
MyApp.m (stack frame 11 in the trace below):
- (void)sendEvent:(UIEvent *)event {
[super sendEvent:event]; // <-- this calls the code above
...
}
The superclass of CommentListMedia is SequentialMedia, which doesn't figure into the stack trace because the exception occurs before it's reached.
Unfortunately I'm only seeing this in crash reports (from Crashlytics), and haven't been able to reproduce it myself. What strikes me as odd about it is that the reference to the class instance must have been good to perform the play selector in the first place, but somehow by the time it gets to the end, the reference to the superclass is bad. At first I thought the instance might be auto-released or something, but I'm under the impression that autoreleasing happens on the main thread at the end of the run loop, not at some random time in the middle of a call. Any input on what might be causing this or how to debug it would be appreciated.
The call stack on the main thread looks like this:
0 libobjc.A.dylib objc_msgSend + 5
1 MyApp -[CommentListMedia play]
2 MyApp -[MediaControls play]
3 UIKit -[UIApplication sendAction:to:from:forEvent:] + 90
4 UIKit -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 30
5 UIKit -[UIControl sendAction:to:forEvent:] + 44
6 UIKit -[UIControl _sendActionsForEvents:withEvent:] + 374
7 UIKit -[UIControl touchesEnded:withEvent:] + 590
8 UIKit -[UIWindow _sendTouchesForEvent:] + 528
9 UIKit -[UIWindow sendEvent:] + 832
10 UIKit -[UIApplication sendEvent:] + 196
11 MyApp -[MyApp sendEvent:]
12 UIKit _UIApplicationHandleEventQueue + 7096
13 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
14 CoreFoundation __CFRunLoopDoSources0 + 206
15 CoreFoundation __CFRunLoopRun + 622
16 CoreFoundation CFRunLoopRunSpecific + 522
17 CoreFoundation CFRunLoopRunInMode + 106
18 GraphicsServices GSEventRunModal + 138
19 UIKit UIApplicationMain + 1136
20 MyApp main
0 libobjc.A.dylib objc_msgSend + 5
1 MyApp -[CommentListMedia play]
That may be a crash in -[SequentialMedia play]. Specifically, if that method returns void and makes a call as the last expression in the method, it may be that the [optimizing] compiler generated a tail call. This would effectively cause the method call to disappear from the stack.
Post the contents of the registers from your crash report. $r0 can be quite illuminating (as it is the first arg and should be a viable object).
Also, if there is heavy concurrency in play in your program, then it could be that the object is being released and deallocated by a secondary thread. But, typically, you would see more than one flavor of odd crash (though sometimes not, if your code makes heavy use of synchronization primitives -- it can be remarkable how consistent a concurrent program behaves from run to run).
I have uploaded the app and it get rejected saying
We found that your app crashed on iPad running iOS 7, which is not in compliance with the App Store Review Guidelines.
Well the time when I uploaded, iOS7 was not launched.
The crash report says
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0xb1b1f20b
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x3a2f5b26 objc_msgSend + 6
1 MapKit 0x30ca46a6 -[MKMapView mapViewDidFinishLoadingTiles:] + 46
2 VectorKit 0x376bbaf4 -[VKTileSource didFinishWithNetwork] + 68
3 VectorKit 0x376bc196 __32-[VKTileSource performDownload:]_block_invoke126 + 38
4 GeoServices 0x345b6fdc ___ZNK49-[GEOTileLoaderInternal _loadedTile:forKey:info:]66__49-[GEOTileLoaderInternal _loadedTile:forKey:info:]_block_invoke3$_1clERKN8LoadItem9RequesterE_block_invoke_2 + 52
5 libdispatch.dylib 0x3a7ddd78 _dispatch_call_block_and_release + 8
6 libdispatch.dylib 0x3a7ddd64 _dispatch_client_callout + 20
7 libdispatch.dylib 0x3a7e47bc _dispatch_main_queue_callback_4CF$VARIANT$mp + 264
8 CoreFoundation 0x2fab881c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 4
9 CoreFoundation 0x2fab70f0 __CFRunLoopRun + 1296
10 CoreFoundation 0x2fa21ce2 CFRunLoopRunSpecific + 518
11 CoreFoundation 0x2fa21ac6 CFRunLoopRunInMode + 102
12 GraphicsServices 0x3471c27e GSEventRunModal + 134
13 UIKit 0x322c3a3c UIApplicationMain + 1132
In crash we see MapKit 0x30ca46a6 -[MKMapView mapViewDidFinishLoadingTiles:].
Is MapKit is giving problem?
For mapkit, below is what I have
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Location";
// Do any additional setup after loading the view.
CLLocationCoordinate2D cords = {29.32511601390379, 48.08847418705136};
MKCoordinateSpan span = {0.008400,0.008400};
region = (MKCoordinateRegion) {cords,span};
mapView.showsUserLocation = YES;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
DisplayMap *ann = [[DisplayMap alloc] init];
ann.coordinate = region.center;
[mapView addAnnotation:ann];
}
Also I don't have dealloc in mapkitviewcontroller. Is that fine? I am asking as this error is related to memory management.
My App was having 5 tabs. First 4 tabs are just UIWebView. For webview, I found that I didn't put webview in dealloc. Below is what I had in webview,
- (void)dealloc {
[super dealloc];
}
Right now I don't have iOS 7 on my xcode too. I need to download that, but thought to ask before here.
Note: All is working perfectly with iOS 6.
Any guesses why I am getting this error?
Did set the map view delegate to nil before navigating away from the page. Also I think there is some memory management issue with IOS maps. So It is better to release maps in the dealloc method.
When I put mapView in dealloc, the problem get solved.
On further investigation, also noticed that I didn't added title for DisplayMap.
DisplayMap *ann = [[DisplayMap alloc] init];
ann.title = #"My Location";
Hello friends I faced problem while creating MAC Application I have two view controllers. when I clicks on button which is placed in first view controller app replace view using below code
- (IBAction)gotoEmployeeView:(id)sender
{
delegate = (AppDelegate *)[[NSApplication sharedApplication]delegate];
secondViewController *employeeVC = [[secondViewController alloc]initWithNibName:#"secondViewController" bundle:nil];
[[delegate.window.contentView animator] replaceSubview:self.view with:secondVC.view];
secondVC.view.frame = ((NSView *)delegate.window.contentView).bounds;
}
now I have one button and I have set click event for this button on second view. below id button click event
- (IBAction)btnClicked:(id)sender
{
NSLog(#"clicked");
}
and when I clicked on it app was crashed. and get below error
2013-08-12 14:33:46.989 Employee Register[1954:303] -[__NSCFString btnClicked:]: unrecognized selector sent to instance 0x10213ace0
2013-08-12 14:33:46.991 Employee Register[1954:303] -[__NSCFString btnClicked:]: unrecognized selector sent to instance 0x10213ace0
2013-08-12 14:33:46.994 Employee Register[1954:303] (
0 CoreFoundation 0x00007fff8d76cf56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff80e47d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8d7f91be -[NSObject doesNotRecognizeSelector:] + 190
3 CoreFoundation 0x00007fff8d759e23 ___forwarding___ + 371
4 CoreFoundation 0x00007fff8d759c38 _CF_forwarding_prep_0 + 232
5 CoreFoundation 0x00007fff8d75c70d -[NSObject performSelector:withObject:] + 61
6 AppKit 0x00007fff8c5208ca -[NSApplication sendAction:to:from:] + 139
7 AppKit 0x00007fff8c5207fe -[NSControl sendAction:to:] + 88
8 AppKit 0x00007fff8c520729 -[NSCell _sendActionFrom:] + 137
9 AppKit 0x00007fff8c51fbec -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2014
10 AppKit 0x00007fff8c59fb74 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 489
11 AppKit 0x00007fff8c51e7f6 -[NSControl mouseDown:] + 786
12 AppKit 0x00007fff8c4e9c98 -[NSWindow sendEvent:] + 6306
13 AppKit 0x00007fff8c4833a5 -[NSApplication sendEvent:] + 5593
14 AppKit 0x00007fff8c419a0e -[NSApplication run] + 555
15 AppKit 0x00007fff8c695eac NSApplicationMain + 867
16 Employee Register 0x0000000100001342 main + 34
17 Employee Register 0x0000000100001314 start + 52
)
It looks like you're sending a btnClicked message to a NSString object. Can you post the code where you call [... bntClicked] ?
The behaviour you are describing can mean either that the viewController implementing the btnClicked method gets deallocated before the action is called or that the action in interface builder is not set correctly.
You should add a log statement in the dealloc method of the viewController implementing the btnClicked and see that it does not get deallocated before the action is called. If you're using ARC make sure that you have a member data pointing to your view controllers so they don't get released.
Also you should delete the ibaction association in interface builder and do it again making sure that you connect the button to the correct view controller.
Your gotoEmployeeView code looks fine to me.
NOTE : replaceSubview:with: method causes oldView to be released.
Take a look at sample project.
So I have an application which uses an NSTimer. The problem is that when the NSTimer runs, my application will crash with EXC_BAD_ACCESS. I only just started with objective-c so I don't know how to properly debug it. If I thought call the -(void)logIn{} with [self logIn]; the application will work.
My code:
.h
#interface DJ_WAppDelegate : NSObject {
NSTimer *loginTimer;
}
-(void)logIn;
#end
.m
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[self logIn]; // this works
loginTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:#selector(logIn) userInfo:nil repeats:YES]; // this fails
}
- (void)logIn {
NSLog(#"Logging in...");
// if I comment out these 2 lines it works with the NSTimer!?... (I've would have more code below)
NSURL *loginConn = [NSURL URLWithString:[NSString stringWithFormat:#"some-website.com"]];
NSInteger loginReturn = [[NSString stringWithContentsOfURL:loginConn encoding:NSASCIIStringEncoding error:nil] intValue];
// when "loginReturn" return "OK" the timer (loginTimer) will be stopped with: [loginTimer invalidate];
// more code would be below... (which works!)
}
So the problem is with the NSURL it think.
Thanks for helping.
EDIT 1:
Here's the crash stack:
EException Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000020
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Application Specific Information:
objc_msgSend() selector name: respondsToSelector:
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x9603bed7 objc_msgSend + 23
1 com.apple.CoreFoundation 0x922ed5f2 _CFStringAppendFormatAndArgumentsAux + 3138
2 com.apple.CoreFoundation 0x922ec979 _CFStringCreateWithFormatAndArgumentsAux + 105
3 com.apple.Foundation 0x9656ebfb -[NSPlaceholderString initWithFormat:locale:arguments:] + 163
4 com.apple.Foundation 0x9656eaae +[NSString stringWithFormat:] + 88
5 com.who.DJ-W 0x00001d56 -[DJ_WAppDelegate logIn] + 116 (DJ_WAppDelegate.m:108)
6 com.apple.Foundation 0x965b08d4 __NSFireTimer + 141
7 com.apple.CoreFoundation 0x922ffadb __CFRunLoopRun + 8059
8 com.apple.CoreFoundation 0x922fd464 CFRunLoopRunSpecific + 452
9 com.apple.CoreFoundation 0x922fd291 CFRunLoopRunInMode + 97
10 com.apple.HIToolbox 0x91646e04 RunCurrentEventLoopInMode + 392
11 com.apple.HIToolbox 0x91646bb9 ReceiveNextEventCommon + 354
12 com.apple.HIToolbox 0x91646a3e BlockUntilNextEventMatchingListInMode + 81
13 com.apple.AppKit 0x9265378d _DPSNextEvent + 847
14 com.apple.AppKit 0x92652fce -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 156
15 com.apple.AppKit 0x92615247 -[NSApplication run] + 821
16 com.apple.AppKit 0x9260d2d9 NSApplicationMain + 574
17 com.who.DJ-W 0x00001c92 start + 54
hope this helps... to find the error
EDIT 2:
With the Zombie Mode on I get this: *** -[CFString respondsToSelector:]: message sent to deallocated instance 0x46d550 I hope this helps.
EDIT 3:
To Ball: Here is the original URL (took away the domain here) /DJW/work.php?user=iBlackbirdi&udid=00000000-0000-1000-80005&key=660e5744e&cmd=slocau&type=get
There are several problems here:
djwLog is a class method so you should call it on the class not the instance
like this: [[self class] djwLog:#"foo bar"]
The URLFromString: method needs the string to contain a valid URL as specified by RFC 1808. Something along the lines of [NSURL URLFromString:#"http://example.com/foo"]
stringWithContentsOfURL:url… is a syncornous method. Unless you have this code running in a separate thread you should not use this. Look at NSURLConnection for a class to asynchronously load data from a URL. Using synchronized calls for this is a bad idea. Always.
intValue returns a signed integer. To get a NSInteger use integerValue. Also if you use stringWithContentsOfURL make sure to check if it's result is nil before calling
integerValue otherwise you might get a result of 0 if the URL call failed or did not return data. A real parser for the API you are calling would be a good idea in any case.
You're calling a class method as if it was an instance method:
[self djwLog:#"Logging in..."];
Since there is no instance-method named djwLog the application crashes. You should either call NSLog directly, make it an instance-method - or preferably make a macro for logging:
#ifdef DEBUG
# define DLog(...) NSLog(#"%s %#", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
#else
# define DLog(...) do { } while (0)
#endif
If you instead of NSLog write DLog - it will only be logging when DEBUG-flag has been defined. In addition to this, it will log the origin of the log message - so you can see which class/method the log entry came from.
The following code for initialization of array works ::
NSArray *array = [[NSArray alloc] initWithObjects:#"Toy Story 3",#"Inception",nil];
self.list = [array sortedArrayUsingSelector:#selector(compare:)];
[array release];
[super viewDidLoad];
But the following code doesnt. The iPhone Simulator Terminates as soon as I try to scroll the Table View which i used to view the array. (Only after i scroll onto empty tableViewCells)
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:#"MovieList" ofType:#"plist"];
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:plistPath];
NSLog([array objectAtIndex:1]);
self.list = [array sortedArrayUsingSelector:#selector(compare:)];
[array release];
[super viewDidLoad];
This was an example app from the Book "Beginning iPhone Development" by Dave Mark. In the example , they have initialized the array within the code, while i have tried to initialize it from a external file.
The console Log ::
2010-12-22 20:57:43.772 Nav[2474:40b] WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWithIndexPath: in <RootViewController: 0x9908870>. Please remove your implementation of this method and set the cell properties accessoryType and/or editingAccessoryType to move to the new cell layout behavior. This method will no longer be called in a future release.
2010-12-22 20:58:12.480 Nav[2474:40b] WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWithIndexPath: in <DisclosureButtonController: 0x9b32ab0>. Please remove your implementation of this method and set the cell properties accessoryType and/or editingAccessoryType to move to the new cell layout behavior. This method will no longer be called in a future release.
2010-12-22 20:59:13.299 Nav[2474:40b] -[UIDeviceRGBColor length]: unrecognized selector sent to instance 0x9b3d900
2010-12-22 20:59:13.301 Nav[2474:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceRGBColor length]: unrecognized selector sent to instance 0x9b3d900'
*** Call stack at first throw:
(
0 CoreFoundation 0x00db2be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f075c2 objc_exception_throw + 47
2 CoreFoundation 0x00db46fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d24366 ___forwarding___ + 966
4 CoreFoundation 0x00d23f22 _CF_forwarding_prep_0 + 50
5 UIKit 0x0051a9ca -[UITableViewCellLayoutManager layoutSubviewsOfCell:] + 3424
6 UIKit 0x00482e02 -[UITableViewCell layoutSubviews] + 95
7 QuartzCore 0x01c70451 -[CALayer layoutSublayers] + 181
8 QuartzCore 0x01c7017c CALayerLayoutIfNeeded + 220
9 QuartzCore 0x01c6937c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
10 QuartzCore 0x01c690d0 _ZN2CA11Transaction6commitEv + 292
11 QuartzCore 0x01c997d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
12 CoreFoundation 0x00d93fbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
13 CoreFoundation 0x00d290e7 __CFRunLoopDoObservers + 295
14 CoreFoundation 0x00cf1bd7 __CFRunLoopRun + 1575
15 CoreFoundation 0x00cf1240 CFRunLoopRunSpecific + 208
16 CoreFoundation 0x00cf1161 CFRunLoopRunInMode + 97
17 GraphicsServices 0x016e7268 GSEventRunModal + 217
18 GraphicsServices 0x016e732d GSEventRun + 115
19 UIKit 0x002ca42e UIApplicationMain + 1160
20 Nav 0x00002598 main + 102
21 Nav 0x00002529 start + 53
)
terminate called after throwing an instance of 'NSException'
enter code here
It sounds like this is a perfect job for the debugger, doesn't it? Why not set a breakpoint on the first line and make sure nothing is unexpectedly nil or out of bounds as you step through and inspect your variables? Perhaps paying attention to the error that's undoubtedly logged to the console might be helpful, too?
Given you've mentioned neither the line on which it terminates nor any log messages, this is about as specific as anyone can get.
The first argument to NSLog needs to be an NSString. The object you're passing to it appears to be part of the UIColor cluster. I suggest you change to:
NSLog(#"%#", [array objectAtIndex:1]);
So the first argument is definitely a string and it says just to print a description of whichever object is the next argument.