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

Commit 645dd25

Browse files
committed
[ios, osx] Fixed crash adding mixture of points and shapes
Fixes #5096.
1 parent 251c41f commit 645dd25

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

platform/ios/src/MGLMapView.mm

+6-2
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,9 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations
27812781
if ( ! annotations) return;
27822782
[self willChangeValueForKey:@"annotations"];
27832783

2784+
NSMutableArray *userPoints = [NSMutableArray array];
27842785
std::vector<mbgl::PointAnnotation> points;
2786+
NSMutableArray *userShapes = [NSMutableArray array];
27852787
std::vector<mbgl::ShapeAnnotation> shapes;
27862788

27872789
NSMutableDictionary *annotationImagesForAnnotation = [NSMutableDictionary dictionary];
@@ -2797,6 +2799,7 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations
27972799
if ([annotation isKindOfClass:[MGLMultiPoint class]])
27982800
{
27992801
[(MGLMultiPoint *)annotation addShapeAnnotationObjectToCollection:shapes withDelegate:self];
2802+
[userShapes addObject:annotation];
28002803
}
28012804
else
28022805
{
@@ -2846,6 +2849,7 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations
28462849
annotationImagesForAnnotation[annotationValue] = annotationImage;
28472850
}
28482851

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

28592863
for (size_t i = 0; i < annotationTags.size(); ++i)
28602864
{
2861-
id<MGLAnnotation> annotation = annotations[i];
2865+
id<MGLAnnotation> annotation = userPoints[i];
28622866
NSValue *annotationValue = [NSValue valueWithNonretainedObject:annotation];
28632867

28642868
MGLAnnotationContext context;
@@ -2890,7 +2894,7 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations
28902894
for (size_t i = 0; i < annotationTags.size(); ++i)
28912895
{
28922896
MGLAnnotationTag annotationTag = annotationTags[i];
2893-
id <MGLAnnotation> annotation = annotations[i];
2897+
id <MGLAnnotation> annotation = userPoints[i];
28942898

28952899
MGLAnnotationContext context;
28962900
context.annotation = annotation;

platform/osx/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## master
44

55
* 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))
6+
* Fixed a crash passing a mixture of point and shape annotations into `-[MGLMapView addAnnotations:]`. ([#5097](https://github.com/mapbox/mapbox-gl-native/pull/5097))
67

78
## 0.1.0
89

platform/osx/src/MGLMapView.mm

+6-2
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,9 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations {
16031603

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

1606+
NSMutableArray *userPoints = [NSMutableArray array];
16061607
std::vector<mbgl::PointAnnotation> points;
1608+
NSMutableArray *userShapes = [NSMutableArray array];
16071609
std::vector<mbgl::ShapeAnnotation> shapes;
16081610
NSMutableArray *annotationImages = [NSMutableArray arrayWithCapacity:annotations.count];
16091611

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

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

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

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

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

16791683
MGLAnnotationContext context;
16801684
context.annotation = annotation;

0 commit comments

Comments
 (0)