CoreLocation 0x34456f78 -[CLLocationManager onClientEventRegistered:] + 384

1

I am facing this error, I want to know where I am wrong.

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)  
Exception Codes: KERN_INVALID_ADDRESS at 0x80000008  
Crashed Thread:  0  

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0  libobjc.A.dylib  0x34499c98 objc_msgSend + 16
1  CoreLocation     0x34456f78 -[CLLocationManager onClientEventRegistered:] + 384
2  CoreLocation     0x34457f42 -[CLLocationManager onClientEvent:supportInfo:] +    46
3  CoreLocation     0x34455a64 OnClientEvent + 16
4  CoreLocation     0x3445178a CLClientInvokeCallback(__CLClient*, CLClientEvent, __CFDictionary const*) + 46
5   CoreLocation                    0x344528cc CLClientHandleDaemonDataRegistration(__CLClient*, CLDaemonCommToClientRegistration const*, __CFDictionary const*) + 700
6   CoreLocation                    0x34453d50 CLClientHandleDaemonData(__CFMessagePort*, long, __CFData const*, void*) + 220
7   CoreFoundation                  0x3094e706 __CFMessagePortPerform + 242
8   CoreFoundation                  0x30957a90 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 20
9   CoreFoundation                  0x30959838 __CFRunLoopDoSource1 + 160
10  CoreFoundation                  0x3095a606 __CFRunLoopRun + 514
11  CoreFoundation                  0x308eaebc CFRunLoopRunSpecific + 224
12  CoreFoundation                  0x308eadc4 CFRunLoopRunInMode + 52
13  GraphicsServices                0x30269418 GSEventRunModal + 108
14  GraphicsServices                0x302694c4 GSEventRun + 56
15  UIKit                           0x30a10d62 -[UIApplication _run] + 398
16  UIKit                           0x30a0e800 UIApplicationMain + 664
17  ProjectOne                      0x00002918 main (main.m:14)
18  ProjectOne                      0x000028cc start + 32

My code :

Start Location :  
-(void)startLocationTracing
 {              
self.TlocationManager = [[CLLocationManager alloc] init];//allocate memeory to locationmanager
self.TlocationManager.desiredAccuracy = kCLLocationAccuracyBest; //Be as accurate as possible   
self.TlocationManager.distanceFilter =  kCLLocationAccuracyBest;                        
self.TlocationManager.delegate = self;      
[self.TlocationManager startUpdatingLocation];  
}

Delegate Method :

- (void)locationManager:(CLLocationManager *)manager 
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation 
{


lat = [NSString stringWithFormat:@"%3.5f",
           newLocation.coordinate.latitude];
lng = [NSString stringWithFormat:@"%3.5f", 
            newLocation.coordinate.longitude];



CLLocation *loc_old = [[CLLocation alloc] initWithLatitude:oldLocation.coordinate.latitude longitude:oldLocation.coordinate.longitude];
CLLocation *loc_new = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];

//get the current distance from the old distance
CLLocationDistance dist = [loc_old distanceFromLocation:loc_new];

// test the age of the location measurement to determine if the measurement is cached
// in most cases you will not want to rely on cached measurement
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 5.0) 
{

    NSLog(@":::::::Location age is greate then 5.0 ::::::::");
    [loc_old release];
    [loc_new release];
    return;

}
float dist_ = (float)dist;//distance in float
NSLog(@"%f", dist_);

[loc_old release];
[loc_new release];



NSString *str_LastLat = [NSString stringWithFormat:@"%@", [[NSUserDefaults standardUserDefaults] valueForKey:@"LastLat"]];
NSString *str_LastLong = [NSString stringWithFormat:@"%@", [[NSUserDefaults standardUserDefaults] valueForKey:@"LastLong"]];


if(([str_LastLat isEqualToString:lat]) && ([str_LastLong isEqualToString:lng]))
{
    //if same lat and long arrives then do not save in the database

    NSLog(@"old and new location are same");

}
else 
{

    if((newLocation.horizontalAccuracy > 0 ) || (newLocation.verticalAccuracy > 0) ){


        [self stopTracingLocations];//to stop location services after the data is sent to 

        objGlobal = [[Global alloc] init];                  
        [objGlobal postLocateValue:lat :lng type:@"TRACING"];  // WCF HIT
        [objGlobal release];

    }

}
}



Stop Location :

-(void)stopTracingLocations
{

[self.TlocationManager stopUpdatingLocation];
self.TlocationManager.delegate = nil;       
if(self.TlocationManager){
    [self.TlocationManager release];
}

}
iphone
ios4
asked on Stack Overflow Sep 1, 2011 by iphone143 • edited Sep 1, 2011 by rckoenes

2 Answers

2

Well it could be due to the fact you are leaking/assining incorectly"

-(void)startLocationTracing {              
   self.TlocationManager = [[[CLLocationManager alloc] init] autorelease];//allocate memeory to locationmanager
   self.TlocationManager.desiredAccuracy = kCLLocationAccuracyBest; //Be as accurate as   possible   
   self.TlocationManager.distanceFilter =  kCLLocationAccuracyBest;                        
   self.TlocationManager.delegate = self;      
   [self.TlocationManager startUpdatingLocation];  
}

-(void)stopTracingLocations {
   [self.TlocationManager stopUpdatingLocation];
   self.TlocationManager.delegate = nil;       
   self.TlocationManager = nil;
}
answered on Stack Overflow Sep 1, 2011 by rckoenes
0

I had the same error. It turns out I was allocating the location manager twice. You might want to see if you're doing that somehow.

It happened to me because I had a sub class calling a super method on init. That super.init allocated a location manager. I forgot about that and allocated it again in the sub classing class.

answered on Stack Overflow Sep 8, 2011 by elise

User contributions licensed under CC BY-SA 3.0