Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6586789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:50:09+00:00 2026-05-25T16:50:09+00:00

I have an app that uses a GoogleMap view. Into that app, I want

  • 0

I have an app that uses a GoogleMap view.
Into that app, I want to display some custom anotations, and a custom view for the userLocation. When the location manager gives a heading, I want to display that custom view for userLocation, if it fails to deliver one, I want the default blue animated dot to come back, etc…

Project and Source code available HERE

Well, there are 2 problems here :

1st problem, THE REALLY BAD ONE. You can play for hours with that tiny app. But… Launch it, wait it loads, send it to the background, put your iPhone in sleep mode, wait a minute, wake up your iPhone, launch the app (that wakes it up) : crash, EXC_BAD_ACCESS. Do the same thing not putting the iPhone in sleep mode : no crash. Not waiting for a minute but a few seconds, no crash. 10 seconds, no crash, 20 seconds, no crash, nears 30 seconds, perhaps a crash, near a minute, crash !

2nd problem (bonus 🙂 ), that can be linked with the first one, but that is not really the heart of this question : the solution I use to achieve the userPinLocation to update from/to the blue pin seems to have a really bad side effect : the userLocation does not move on the map as you move in the street. For any answer for that 2nd problem, if it’s not directly linked with the crash, please use comments not answers. This is not the heart of the question… I think…

To find the faulty code, I’ve reduced my app at its minimum. That gives the following code (some tips in the source code as comments) :

EXC_BAD_ACCESS_TestViewController.h

#import <MapKit/MapKit.h>

@interface EXC_BAD_ACCESS_TestViewController : UIViewController<CLLocationManagerDelegate> {

    CLLocationManager* locationMgr;
    NSMutableArray* customAnnotations;
    CLLocationDirection userHeading;
    MKMapView* myMapView;
}

@property(nonatomic, retain) CLLocationManager* locationMgr;
@property(nonatomic, retain) NSMutableArray* customAnnotations;
@property(nonatomic, assign) CLLocationDirection userHeading;
@property(nonatomic, retain) IBOutlet MKMapView* myMapView;

- (void) loadAnnotations;

@end

EXC_BAD_ACCESS_TestViewController.m

// On first launch, due to code simplification, the app may crash when asked authorization to use geo hardware. Just kill/relaunch after accepting.
// Breakpoints on each method entry : EXC_BAD_ACCESS crash without any break-stop

#import "EXC_BAD_ACCESS_TestViewController.h"
#import "CustomAnnotation.h"

@implementation EXC_BAD_ACCESS_TestViewController

@synthesize locationMgr, customAnnotations, myMapView, userHeading;

// ===========================================================================================================
-(id) initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (!self) return nil;

    self.userHeading = -1;

    return self;
}

// ===========================================================================================================
- (void) viewDidLoad
{
    [self loadAnnotations];

    self.myMapView.mapType = MKMapTypeStandard;
    self.myMapView.showsUserLocation = YES;

    // -----------------------------------------------
    // Just comment this sole line : no more crash
    // -----------------------------------------------
    for (CustomAnnotation* pin in self.customAnnotations) [self.myMapView addAnnotation:pin];

    // locationManager
    self.locationMgr = [[CLLocationManager alloc] init];
    self.locationMgr.desiredAccuracy = kCLLocationAccuracyBest;
    self.locationMgr.distanceFilter = 1.0;
    self.locationMgr.headingFilter = 1.0;
    self.locationMgr.purpose = @"Some purpose.";
    self.locationMgr.delegate = self;
    [self.locationMgr startUpdatingHeading];

    [super viewDidLoad];
}

// ===========================================================================================================
- (void) loadAnnotations
{   
    // Code for testing, real code gets the datas using another way of doing, as simple as this one
    self.customAnnotations = [NSMutableArray array];
    double latitude = 45.0;
    double longitude = -45.0;

    for (int i=1; i<=400; i++) {
        CLLocationCoordinate2D pinLocation = CLLocationCoordinate2DMake(latitude, longitude);
        CustomAnnotation* pin = [[[CustomAnnotation alloc] initWithCoordinate:pinLocation] autorelease];            
        [self.customAnnotations addObject:pin];

        latitude += 0.01;
        longitude += 0.01;
    }
}

// ===========================================================================================================
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
    MKAnnotationView* pinView = nil;
    NSString* annotationIdentifier;
    UIImage* pinImage;
    BOOL canShowCallout;

    // User location
    if ([annotation isKindOfClass:[MKUserLocation class]] && self.userHeading >= 0) {
        annotationIdentifier = @"UserLocationAnnotation";
        pinImage = [UIImage imageNamed:@"custom_userlocation.png"];
        canShowCallout = NO;
    }
    // Custom Pin
    else if ([annotation isKindOfClass:[CustomAnnotation class]]) {
        annotationIdentifier = @"CustomAnnotation";
        pinImage = [UIImage imageNamed:@"custom_pin.png"];
        canShowCallout = YES;
    }
    // Others
    else {
        return nil;
    }

    pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];

    if (pinView) {
        pinView.annotation = annotation;
    }
    else {
        pinView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier] autorelease];
        if (pinView) {
            pinView.image = pinImage;
            pinView.canShowCallout = canShowCallout;

            if (canShowCallout) {
                pinView.calloutOffset = CGPointMake(-5, 5);
                pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            }
        }
    }

    return pinView;
}

// -----------------------------------------------
// Just comment this method : no more crash
// -----------------------------------------------
// ===========================================================================================================
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    if (!self.myMapView) return;
    if (!self.myMapView.userLocation) return;

    CLLocationDirection compassHeading_True = newHeading.trueHeading;
    CLLocationDirection compassHeading_Magnetic = newHeading.magneticHeading;

    CLLocationDirection heading;
    if (compassHeading_True == -1)              heading = compassHeading_Magnetic;
    else if (newHeading.headingAccuracy >= 0)   heading = compassHeading_True;
    else                                        heading = -1;

    // If we get/loose the heading, update pin image
    // I didn't found any other solution to force the user pin to update its display.
    if ((self.userHeading == -1 || heading == -1) && self.userHeading != heading) {
        [self.myMapView removeAnnotation:self.myMapView.userLocation];
        self.userHeading = heading;
        [self.myMapView addAnnotation:self.myMapView.userLocation];
    }

    self.userHeading = heading;

    // ------------------------------------
    // Some non bugued code was there
    // ------------------------------------
}

// ===========================================================================================================
- (void) dealloc
{   
    self.myMapView = nil;
    self.customAnnotations = nil;
    self.locationMgr = nil;

    [super dealloc];
}

@end

CustomAnnotation.h

#import <MapKit/MapKit.h>

@interface CustomAnnotation : NSObject<MKAnnotation> {
    CLLocationCoordinate2D coordinate;
}

@property(nonatomic, assign) CLLocationCoordinate2D coordinate;

- (id)initWithCoordinate:(CLLocationCoordinate2D) c;
@end

CustomAnnotation.m

#import "CustomAnnotation.h"

@implementation CustomAnnotation

@synthesize coordinate;

// ===========================================================================================================
- (id)initWithCoordinate:(CLLocationCoordinate2D) c
{
    self = [super init];
    if (!self) return nil;

    self.coordinate = c;

    return self;
}

// ===========================================================================================================
- (NSString*)subtitle 
{
    return @"";
}

// ===========================================================================================================
- (NSString*)title 
{
    return @"";
}

@end

I tried breakpoints in each methods, trying to enable Zombies with environment variables (but as this needs to be ran on the device, I’m not sure they’ve been really activated), without any start of solution… I still don’t have any idea of what’s going wrong.

Do you see how to solve that EXC_BAD_ACCESS problem ?
For any answer for the 2nd problem, please use comments and not answers if it don’t solve the crash. This problem is not the heart of the question as far as I’ve seen.

Tip : I’ve put 2 comments in the code above where I found some start of solution. There are 2 places, that does not seems connected, that can be put out of the code one OR the other to solve the problem. What makes me crazy is the OR.

Runned on an iPhone 4 ios 4.2.1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:50:09+00:00Added an answer on May 25, 2026 at 4:50 pm
    [self.myMapView removeAnnotation:self.myMapView.userLocation];
    

    This line is causing the crash from stacktrace this is what I’ve seen.

    When I saw exc_bad_access I did a bt in gdb. I have added Guard Malloc breakpoint. Looking at the stack it said about removing annotation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have war app that uses reasteasy to expose some services. I want to
I have a Cocoa app that uses a WebView to display an HTML interface.
I have a C++ app that uses standard socket calls and I want to
I have an app that uses some code scripts to generate dll's at run-time
i have an app that uses a navbar. What i want to acomplish is
I have an app that uses sharekit to submit stuff to Twitter. I want
I have an app that uses maps. I want to give the user the
I have an app that uses the CLLocationManager to receive location and heading updates.
I have an app that uses Javascript to perform some calculations and then plot
I have an app that uses a couple of SOA calls to get some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.