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

Commit 30e59ce

Browse files
authoredNov 16, 2017
Monkey crashes (#10440) (#10472)
* [android] - avoid null map from trackballevent * [android] - fixup animated marker test activity from monkey runs * [android] - harden NativeMapView OnMapChangeListener * [android] - harden against destroyed wrapper activity while moving touch pointers * [android] - harden bulk marker activity for monkey runner * [android] - harden scale end gesture event for null velocity tracker * [android] - invalid mapboxMap invocation * [android] - reset test setup
1 parent 1049c01 commit 30e59ce

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed
 

‎platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,10 @@ boolean onTouchEvent(MotionEvent event) {
235235
velocityTracker = null;
236236
break;
237237
case MotionEvent.ACTION_MOVE:
238-
velocityTracker.addMovement(event);
239-
velocityTracker.computeCurrentVelocity(1000);
238+
if (velocityTracker != null) {
239+
velocityTracker.addMovement(event);
240+
velocityTracker.computeCurrentVelocity(1000);
241+
}
240242
break;
241243
}
242244

@@ -551,6 +553,11 @@ public boolean onScale(ScaleGestureDetector detector) {
551553
// Called when fingers leave screen
552554
@Override
553555
public void onScaleEnd(final ScaleGestureDetector detector) {
556+
if (velocityTracker == null) {
557+
return;
558+
}
559+
560+
554561
if (rotateGestureOccurred || quickZoom) {
555562
reset();
556563
return;

‎platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,9 @@ int getHeight() {
10821082
//
10831083

10841084
void addOnMapChangedListener(@NonNull MapView.OnMapChangedListener listener) {
1085-
mapView.addOnMapChangedListener(listener);
1085+
if (mapView != null) {
1086+
mapView.addOnMapChangedListener(listener);
1087+
}
10861088
}
10871089

10881090
void removeOnMapChangedListener(@NonNull MapView.OnMapChangedListener listener) {

‎platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,18 @@ void setZoom(double zoom, @NonNull PointF focalPoint) {
238238
}
239239

240240
void setZoom(double zoom, @NonNull PointF focalPoint, long duration) {
241-
mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
242-
@Override
243-
public void onMapChanged(int change) {
244-
if (change == MapView.REGION_DID_CHANGE_ANIMATED) {
245-
cameraChangeDispatcher.onCameraIdle();
246-
mapView.removeOnMapChangedListener(this);
241+
if (mapView != null) {
242+
mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
243+
@Override
244+
public void onMapChanged(int change) {
245+
if (change == MapView.REGION_DID_CHANGE_ANIMATED) {
246+
cameraChangeDispatcher.onCameraIdle();
247+
mapView.removeOnMapChangedListener(this);
248+
}
247249
}
248-
}
249-
});
250-
mapView.setZoom(zoom, focalPoint, duration);
250+
});
251+
mapView.setZoom(zoom, focalPoint, duration);
252+
}
251253
}
252254

253255
// Direction

‎platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedMarkerActivity.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,14 @@ protected void onStop() {
236236

237237
stopped = true;
238238

239-
// Stop ongoing animations, prevent memory lekas
240-
MarkerViewManager markerViewManager = mapboxMap.getMarkerViewManager();
241-
for (MarkerView markerView : markerViews) {
242-
View view = markerViewManager.getView(markerView);
243-
if (view != null) {
244-
view.animate().cancel();
239+
// Stop ongoing animations, prevent memory leaks
240+
if (mapboxMap != null) {
241+
MarkerViewManager markerViewManager = mapboxMap.getMarkerViewManager();
242+
for (MarkerView markerView : markerViews) {
243+
View view = markerViewManager.getView(markerView);
244+
if (view != null) {
245+
view.animate().cancel();
246+
}
245247
}
246248
}
247249

‎platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ private void onLatLngListLoaded(List<LatLng> latLngs, int amount) {
100100
}
101101

102102
private void showMarkers(int amount) {
103+
if (mapboxMap == null || locations == null) {
104+
return;
105+
}
106+
103107
mapboxMap.clear();
104108

105109
if (locations.size() < amount) {

0 commit comments

Comments
 (0)
This repository has been archived.