diff options
3 files changed, 21 insertions, 5 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java index e757907ab8..06539ae21d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java @@ -1,5 +1,6 @@ package com.mapbox.mapboxsdk.maps.renderer.glsurfaceview; +import android.annotation.SuppressLint; import android.content.Context; import android.opengl.GLSurfaceView; @@ -43,6 +44,11 @@ public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceVi GLSurfaceViewMapRenderer.this.onSurfaceDestroyed(); } + @Override + public void surfaceCreated(SurfaceHolder holder) { + GLSurfaceViewMapRenderer.super.onSurfaceCreated(null, null); + } + }); } @@ -58,7 +64,7 @@ public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceVi @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { - super.onSurfaceCreated(gl, config); + //super.onSurfaceCreated(gl, config); } @Override diff --git a/platform/android/src/map_renderer.cpp b/platform/android/src/map_renderer.cpp index cff021afd2..135905c277 100644 --- a/platform/android/src/map_renderer.cpp +++ b/platform/android/src/map_renderer.cpp @@ -125,7 +125,9 @@ void MapRenderer::scheduleSnapshot(std::unique_ptr<SnapshotCallback> callback) { } void MapRenderer::render(JNIEnv&) { - assert (renderer); + if (!renderer) { + return; + } std::shared_ptr<UpdateParameters> params; { @@ -159,6 +161,12 @@ void MapRenderer::render(JNIEnv&) { } void MapRenderer::onSurfaceCreated(JNIEnv&) { + // Make sure to create the surface of the renderer on the GL Thread + auto self = ActorRef<MapRenderer>(*this, mailbox); + self.ask(&MapRenderer::createRenderer).wait(); +} + +void MapRenderer::createRenderer() { // Lock as the initialization can come from the main thread or the GL thread first std::lock_guard<std::mutex> lock(initialisationMutex); diff --git a/platform/android/src/map_renderer.hpp b/platform/android/src/map_renderer.hpp index 8c2f28a4df..0c3c01b93e 100644 --- a/platform/android/src/map_renderer.hpp +++ b/platform/android/src/map_renderer.hpp @@ -90,11 +90,13 @@ private: // Renders a frame. void render(JNIEnv&); - void onSurfaceCreated(JNIEnv&); - void onSurfaceChanged(JNIEnv&, jint width, jint height); - // Called on Main thread + void createRenderer(); + + // Called from the Main thread // + void onSurfaceCreated(JNIEnv&); + void onSurfaceDestroyed(JNIEnv&); private: |