summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun Van Nuland <tobrun.van.nuland@gmail.com>2017-08-17 10:32:49 +0200
committerTobrun <tobrun@mapbox.com>2017-08-19 11:29:38 +0200
commit341165cef44c7ecd67f3a911eb29e0433d33e14c (patch)
treeb08060214dd5aef84bd3e6bcf3a1ccb032296584
parentf356ff4b0047179d42e25d46578fc464e341ee5d (diff)
downloadqtlocation-mapboxgl-341165cef44c7ecd67f3a911eb29e0433d33e14c.tar.gz
[android] - avoid IndexOutOfBounds when destroying map object
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java46
1 files changed, 18 insertions, 28 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java
index 712ab67de0..d15d5eddf8 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java
@@ -212,22 +212,19 @@ class AnnotationManager {
}
if (markers.size() > 0) {
- long[] ids = null;
+ long[] ids;
if (nativeMapView != null) {
ids = nativeMapView.addMarkers(markers);
+ } else {
+ ids = new long[markers.size()];
}
- long id = 0;
+ long id;
Marker m;
- for (int i = 0; i < markers.size(); i++) {
+ for (int i = 0; i < ids.length; i++) {
m = markers.get(i);
m.setMapboxMap(mapboxMap);
- if (ids != null) {
- id = ids[i];
- } else {
- // unit test
- id++;
- }
+ id = ids[i];
m.setId(id);
annotations.put(id, m);
}
@@ -481,21 +478,18 @@ class AnnotationManager {
}
}
- long[] ids = null;
+ long[] ids;
if (nativeMapView != null) {
ids = nativeMapView.addPolygons(polygons);
+ } else {
+ ids = new long[polygons.size()];
}
- long id = 0;
- for (int i = 0; i < polygons.size(); i++) {
+ long id;
+ for (int i = 0; i < ids.length; i++) {
polygon = polygons.get(i);
polygon.setMapboxMap(mapboxMap);
- if (ids != null) {
- id = ids[i];
- } else {
- // unit test
- id++;
- }
+ id = ids[i];
polygon.setId(id);
shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + id);
annotations.put(id, polygon);
@@ -555,23 +549,19 @@ class AnnotationManager {
}
}
- long[] ids = null;
+ long[] ids;
if (nativeMapView != null) {
ids = nativeMapView.addPolylines(polylines);
+ } else {
+ ids = new long[polylines.size()];
}
- long id = 0;
+ long id;
Polyline p;
-
- for (int i = 0; i < polylines.size(); i++) {
+ for (int i = 0; i < ids.length; i++) {
p = polylines.get(i);
p.setMapboxMap(mapboxMap);
- if (ids != null) {
- id = ids[i];
- } else {
- // unit test
- id++;
- }
+ id = ids[i];
p.setId(id);
shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + id);
annotations.put(id, p);