2

I have problems analyzing my crashlog. The iPhone crashes sometimes, when I click on the app icon to start the app. The app is already "running" in background, but it's not active. This is the symbolized crash log:

Thread 0 Crashed:
0   libobjc.A.dylib     0x33479470 objc_msgSend + 28
1   CoreLocation                    0x3436f68e -[CLLocationManager onClientEvent:supportInfo:] + 98
2   CoreLocation                    0x3436f804 OnClientEvent + 16
3   CoreLocation                    0x3436b522 CLClientInvokeCallback(__CLClient*, CLClientEvent, __CFDictionary const*) + 42
4   CoreLocation                    0x3436cf74 CLClientHandleDaemonDataRegistration(__CLClient*, CLDaemonCommToClientRegistration const*, __CFDictionary const*) + 668
5   CoreLocation                    0x3436d4c8 CLClientHandleDaemonData(__CFMessagePort*, long, __CFData const*, void*) + 212
6   CoreFoundation                  0x33a813fe __CFMessagePortPerform + 242
7   CoreFoundation                  0x33a556f8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 20
8   CoreFoundation                  0x33a556bc __CFRunLoopDoSource1 + 160
9   CoreFoundation                  0x33a47f76 __CFRunLoopRun + 514
10  CoreFoundation                  0x33a47c80 CFRunLoopRunSpecific + 224
11  CoreFoundation                  0x33a47b88 CFRunLoopRunInMode + 52
12  GraphicsServices                0x33b0e4a4 GSEventRunModal + 108
13  GraphicsServices                0x33b0e550 GSEventRun + 56
14  UIKit   0x32099322 -[UIApplication _run] + 406
15  UIKit                           0x32096e8c UIApplicationMain + 664
16  Norddeich                       0x00002764 main (main.m:14)
17  Norddeich                       0x00002718 start + 32

As far as i understand the stack trace, the error occurred in the main.m. Line 14 is part of the default code:

int retVal = UIApplicationMain(argc, argv, nil, nil);

Please give me a hint, how to find the error.
Thank you in advance!

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
sqeez3r
  • 495
  • 6
  • 16
  • Seems like some code in `CLLocationManager` is crashing. Do you use location tracking in your app? – Ole Begemann Mar 06 '11 at 19:43
  • Hi Ole! Yes, I use location tracking. I have a CLLocationManager in the AppDelegate which I start in the didFinishLaunchingWithOptions method. Every time when a view controller is used which needs the location, I set the view controller as the CLLocationManager's delegate in order to use the appropriate didUpdateToLocation method. Is this OK? Thanks! – sqeez3r Mar 06 '11 at 20:31
  • Do you set the delegate to nil when entering the background? If not, the view controller which has been set as the delegate could have been deallocated, which would be causing the crash. Also, you need to look at the top of the crash log to see where it occurred. If the crash is on thread 0, then your main function will always be at the bottom of the backtrace. – ughoavgfhw Mar 07 '11 at 00:41

2 Answers2

5

Do you set it's delegate to nil before returning from controller (or at least in controller's dealloc)? I suspect CLLocationManager is trying to send a message to delegate which is deallocated already - that's why it crashes at obj_msgSend.

hoha
  • 4,418
  • 17
  • 15
  • & @ughoavgfhw: You are both absolutely right! I forget to set the delegate to nil. I thought that this would not become a problem, because there must be a an allocated view controller at every time. So thank you very much for your help! I now set the GLLocationManager in the viewWillDisappear method to nil and I hope the app won't crash anymore. – sqeez3r Mar 07 '11 at 19:28
0

I had this same problem testing my app on 4.3, but not in 5.0. The issue was that I was trying to dealloc the CLLocationManager inside one of the delegate methods. It works fine in 5.0, but crashes a iPhone 3GS running 4.3 every time.

In the end I made the CLLocationManager object a property, then in the delegate method set the delegate to nil and dispatched a block to the main thread to release the object.

David H
  • 40,852
  • 12
  • 92
  • 138