From 70e18e5e68fcf23fe4e74b310da9b56492019067 Mon Sep 17 00:00:00 2001 From: hashfunction Date: Wed, 27 Dec 2017 12:21:21 -0800 Subject: [PATCH 1/2] [android] Fixes #10563 NPE addAnnotationIcon --- .../src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 49318e277a7..fbf424e048f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -321,6 +321,10 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) { MapView.this.post(new Runnable() { @Override public void run() { + // There is no guarantee that onDestroy will not be called before the surface is created + if (destroyed) { + return; + } // Initialise only once if (mapboxMap == null) { initialiseMap(); From 1cbb8976a49615f62dcfe8dd6e52589ae0f33035 Mon Sep 17 00:00:00 2001 From: tobrun Date: Tue, 2 Jan 2018 11:30:48 +0100 Subject: [PATCH 2/2] [android] - refactor surface destruction NPE fix --- .../com/mapbox/mapboxsdk/maps/MapView.java | 53 +++++++------------ 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index fbf424e048f..256f49ef52e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -22,7 +22,6 @@ import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.ZoomButtonsController; - import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.annotations.Annotation; import com.mapbox.mapboxsdk.annotations.MarkerViewManager; @@ -37,7 +36,10 @@ import com.mapbox.mapboxsdk.net.ConnectivityReceiver; import com.mapbox.mapboxsdk.storage.FileSource; import com.mapbox.services.android.telemetry.MapboxTelemetry; +import timber.log.Timber; +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.opengles.GL10; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; @@ -45,11 +47,6 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.opengles.GL10; - -import timber.log.Timber; - import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_MAP_NORTH_ANIMATION; import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_WAIT_IDLE; @@ -296,55 +293,43 @@ private void initialiseDrawingSurface(MapboxMapOptions options) { mapRenderer = new TextureViewMapRenderer(getContext(), textureView, options.getLocalIdeographFontFamily()) { @Override protected void onSurfaceCreated(GL10 gl, EGLConfig config) { - MapView.this.post(new Runnable() { - @Override - public void run() { - // Initialise only once - if (mapboxMap == null) { - initialiseMap(); - mapboxMap.onStart(); - } - } - }); - + initRenderSurface(); super.onSurfaceCreated(gl, config); } }; + addView(textureView, 0); } else { GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView); glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop()); - mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView, options.getLocalIdeographFontFamily()) { @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { - MapView.this.post(new Runnable() { - @Override - public void run() { - // There is no guarantee that onDestroy will not be called before the surface is created - if (destroyed) { - return; - } - // Initialise only once - if (mapboxMap == null) { - initialiseMap(); - mapboxMap.onStart(); - } - } - }); - + initRenderSurface(); super.onSurfaceCreated(gl, config); } }; glSurfaceView.setVisibility(View.VISIBLE); - } nativeMapView = new NativeMapView(this, mapRenderer); nativeMapView.resizeView(getMeasuredWidth(), getMeasuredHeight()); } + private void initRenderSurface() { + post(new Runnable() { + @Override + public void run() { + // Initialise only when not destroyed and only once + if (!destroyed && mapboxMap == null) { + initialiseMap(); + mapboxMap.onStart(); + } + } + }); + } + /** * You must call this method from the parent's Activity#onSaveInstanceState(Bundle) * or Fragment#onSaveInstanceState(Bundle).