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

Commit

Permalink
[android] - avoid IndexOutOfBounds when destroying map object
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Aug 17, 2017
1 parent 71e7759 commit 7335566
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public List<Marker> addBy(@NonNull List<? extends BaseMarkerOptions> markerOptio
mapboxMap) {
int count = markerOptionsList.size();
List<Marker> markers = new ArrayList<>(count);
if (count > 0) {
if (nativeMapView != null && count > 0) {
BaseMarkerOptions markerOptions;
Marker marker;
for (int i = 0; i < count; i++) {
Expand All @@ -63,26 +63,13 @@ public List<Marker> addBy(@NonNull List<? extends BaseMarkerOptions> markerOptio
}

if (markers.size() > 0) {
long[] ids = null;
if (nativeMapView != null) {
ids = nativeMapView.addMarkers(markers);
long[] ids = nativeMapView.addMarkers(markers);
for (int i = 0; i < ids.length; i++) {
Marker createdMarker = markers.get(i);
createdMarker.setMapboxMap(mapboxMap);
createdMarker.setId(ids[i]);
annotations.put(ids[i], createdMarker);
}

long id = 0;
Marker m;
for (int i = 0; i < markers.size(); i++) {
m = markers.get(i);
m.setMapboxMap(mapboxMap);
if (ids != null) {
id = ids[i];
} else {
// unit test
id++;
}
m.setId(id);
annotations.put(id, m);
}

}
}
return markers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,20 @@ public List<Polygon> addBy(@NonNull List<PolygonOptions> polygonOptionsList, @No

Polygon polygon;
List<Polygon> polygons = new ArrayList<>(count);
if (count > 0) {
if (nativeMapView != null && count > 0) {
for (PolygonOptions polygonOptions : polygonOptionsList) {
polygon = polygonOptions.getPolygon();
if (!polygon.getPoints().isEmpty()) {
polygons.add(polygon);
}
}

long[] ids = null;
if (nativeMapView != null) {
ids = nativeMapView.addPolygons(polygons);
}

long id = 0;
for (int i = 0; i < polygons.size(); i++) {
long[] ids = nativeMapView.addPolygons(polygons);
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++;
}
polygon.setId(id);
annotations.put(id, polygon);
polygon.setId(ids[i]);
annotations.put(ids[i], polygon);
}
}
return polygons;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,20 @@ public List<Polyline> addBy(@NonNull List<PolylineOptions> polylineOptionsList,
int count = polylineOptionsList.size();
Polyline polyline;
List<Polyline> polylines = new ArrayList<>(count);

if (count > 0) {
if (nativeMapView != null && count > 0) {
for (PolylineOptions options : polylineOptionsList) {
polyline = options.getPolyline();
if (!polyline.getPoints().isEmpty()) {
polylines.add(polyline);
}
}

long[] ids = null;
if (nativeMapView != null) {
ids = nativeMapView.addPolylines(polylines);
}

long id = 0;
Polyline p;

for (int i = 0; i < polylines.size(); i++) {
p = polylines.get(i);
p.setMapboxMap(mapboxMap);
if (ids != null) {
id = ids[i];
} else {
// unit test
id++;
}
p.setId(id);
annotations.put(id, p);
long[] ids = nativeMapView.addPolylines(polylines);
for (int i = 0; i < ids.length; i++) {
Polyline polylineCreated = polylines.get(i);
polylineCreated.setMapboxMap(mapboxMap);
polylineCreated.setId(ids[i]);
annotations.put(ids[i], polylineCreated);
}
}
return polylines;
Expand Down

0 comments on commit 7335566

Please sign in to comment.