Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Fix crash adding mixture of points and shapes #5097

Merged
merged 1 commit into from
May 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2781,7 +2781,9 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations
if ( ! annotations) return;
[self willChangeValueForKey:@"annotations"];

NSMutableArray *userPoints = [NSMutableArray array];
std::vector<mbgl::PointAnnotation> points;
NSMutableArray *userShapes = [NSMutableArray array];
std::vector<mbgl::ShapeAnnotation> shapes;

NSMutableDictionary *annotationImagesForAnnotation = [NSMutableDictionary dictionary];
Expand All @@ -2797,6 +2799,7 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations
if ([annotation isKindOfClass:[MGLMultiPoint class]])
{
[(MGLMultiPoint *)annotation addShapeAnnotationObjectToCollection:shapes withDelegate:self];
[userShapes addObject:annotation];
}
else
{
Expand Down Expand Up @@ -2846,6 +2849,7 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations
annotationImagesForAnnotation[annotationValue] = annotationImage;
}

[userPoints addObject:annotation];
points.emplace_back(MGLLatLngFromLocationCoordinate2D(annotation.coordinate), symbolName.UTF8String ?: "");
}
}
Expand All @@ -2858,7 +2862,7 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations

for (size_t i = 0; i < annotationTags.size(); ++i)
{
id<MGLAnnotation> annotation = annotations[i];
id<MGLAnnotation> annotation = userPoints[i];
NSValue *annotationValue = [NSValue valueWithNonretainedObject:annotation];

MGLAnnotationContext context;
Expand Down Expand Up @@ -2890,7 +2894,7 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations
for (size_t i = 0; i < annotationTags.size(); ++i)
{
MGLAnnotationTag annotationTag = annotationTags[i];
id <MGLAnnotation> annotation = annotations[i];
id <MGLAnnotation> annotation = userPoints[i];

MGLAnnotationContext context;
context.annotation = annotation;
Expand Down
1 change: 1 addition & 0 deletions platform/osx/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## master

* Fixed an issue in which Mapbox.framework was nested inside another folder named Mapbox.framework. ([#4998](https://github.com/mapbox/mapbox-gl-native/pull/4998))
* Fixed a crash passing a mixture of point and shape annotations into `-[MGLMapView addAnnotations:]`. ([#5097](https://github.com/mapbox/mapbox-gl-native/pull/5097))

## 0.1.0

Expand Down
8 changes: 6 additions & 2 deletions platform/osx/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,9 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations {

BOOL delegateHasImagesForAnnotations = [self.delegate respondsToSelector:@selector(mapView:imageForAnnotation:)];

NSMutableArray *userPoints = [NSMutableArray array];
std::vector<mbgl::PointAnnotation> points;
NSMutableArray *userShapes = [NSMutableArray array];
std::vector<mbgl::ShapeAnnotation> shapes;
NSMutableArray *annotationImages = [NSMutableArray arrayWithCapacity:annotations.count];

Expand All @@ -1613,6 +1615,7 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations {
if ([annotation isKindOfClass:[MGLMultiPoint class]]) {
// The multipoint knows how to style itself (with the map view’s help).
[(MGLMultiPoint *)annotation addShapeAnnotationObjectToCollection:shapes withDelegate:self];
[userShapes addObject:annotation];
} else {
MGLAnnotationImage *annotationImage = nil;
if (delegateHasImagesForAnnotations) {
Expand All @@ -1637,6 +1640,7 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations {
}
[annotationImages addObject:annotationImage];

[userPoints addObject:annotation];
points.emplace_back(MGLLatLngFromLocationCoordinate2D(annotation.coordinate), symbolName.UTF8String ?: "");

// Opt into potentially expensive tooltip tracking areas.
Expand All @@ -1654,7 +1658,7 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations {
MGLAnnotationTag annotationTag = annotationTags[i];
MGLAnnotationImage *annotationImage = annotationImages[i];
annotationImage.styleIconIdentifier = @(points[i].icon.c_str());
id <MGLAnnotation> annotation = annotations[i];
id <MGLAnnotation> annotation = userPoints[i];

MGLAnnotationContext context;
context.annotation = annotation;
Expand All @@ -1674,7 +1678,7 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations {

for (size_t i = 0; i < annotationTags.size(); ++i) {
MGLAnnotationTag annotationTag = annotationTags[i];
id <MGLAnnotation> annotation = annotations[i];
id <MGLAnnotation> annotation = userShapes[i];

MGLAnnotationContext context;
context.annotation = annotation;
Expand Down