iphone - MKMapView addAnnotation crashing with EXC_BAD_ACCESS -
hello seeing weird issue, populating own custom annotation mkmapview in loop, after running loop 54 times on 55th times when mkmapview addannotation on line throws exc_bad_access here code
- (void)viewdidload { [super viewdidload]; [mkmapview setmaptype:mkmaptypestandard]; [mkmapview setzoomenabled:yes]; [mkmapview setshowsuserlocation:yes]; [mkmapview setscrollenabled:yes]; mkcoordinateregion region; region.center.latitude = currentlocation.latitude; region.center.longitude = currentlocation.longitude; mkcoordinatespan span; span.latitudedelta = 0.03; span.longitudedelta = 0.03; region.span = span; [mkmapview setregion:region animated:true]; [mkmapview setdelegate:self]; int =0; for(myobject* myobject in myobjectarray) { nslog(@"%d", i); if(i == 55){ nslog(@"%@", myobject); } i++; nsstring *maintitle = myobject.name; nsstring *subtitle = myobject.address; cllocationcoordinate2d newcoordinate = { [myobject.latitude doublevalue], [myobject.longitude doublevalue] }; annotation *pinannotation = [[annotation alloc]initwithcoordinate:newcoordinate title:maintitle subtitle:subtitle image:null]; [mkmapview addannotation: pinannotation]; [pinannotation release]; } } - (void)dealloc { mkmapview.delegate = nil; [mkmapview release]; mkmapview = nil; [myobjectarray release]; myobjectarray = nil; [super dealloc]; }
here code annotation.h
@interface annotation : nsobject <mkannotation>{ cllocationcoordinate2d coordinate; nsstring * title; nsstring * subtitle; uiimage * image; } @property (nonatomic, readwrite, assign) cllocationcoordinate2d coordinate; @property (nonatomic, retain) nsstring * title; @property (nonatomic, retain) nsstring * subtitle; @property (nonatomic, retain) uiimage * image; - (id) initwithcoordinate:(cllocationcoordinate2d) coordinate title:(nsstring*) title subtitle:(nsstring*) subtitle image:(uiimage*) image; @end
here code annotation.m
- (id) initwithcoordinate:(cllocationcoordinate2d)coordinate title:(nsstring*) title subtitle: (nsstring*) subtitle image:(uiimage*) image{ self = [super init]; if(self){ self.coordinate = coordinate; self.title = title; self.subtitle = subtitle; self.image = image; } return self; } -(void) dealloc{ [title release]; [subtitle release]; [image release]; [super dealloc]; }
here stacktrace
0 myapp 0x00099c6a +[tfcrashhandler backtrace] + 46
1 myapp 0x0009a007 tfsignalhandler + 45
2 libsystem.b.dylib 0x9455345b _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 mapkit 0x015f5124 -[mkquadtrie contains:] + 40
5 mapkit 0x0156363c -[mkannotationcontainerview addannotation:] + 356
6 mapkit 0x01538807 -[mkmapview addannotation:] + 115
make sure annotations you're trying add has sane coordinates, common source of crashes when adding them mkmapview.
latitudes should between -90 , 90 , longitudes should between -180 , 180.
Comments
Post a Comment