diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-11-03 11:33:00 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2017-11-03 09:19:39 -0700 |
commit | d1d0c200442133e2eca110e3521f1caf831eda5c (patch) | |
tree | 0c3393a0e6d005aa4ee60b8248b783d885292ca6 /platform/android/MapboxGLAndroidSDK | |
parent | 8753edf08f4634a9f49020741464a6b7dc61cf2d (diff) | |
download | qtlocation-mapboxgl-d1d0c200442133e2eca110e3521f1caf831eda5c.tar.gz |
[android] TextureView - cleanup destruction code
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java index 3ed55b634a..c34833e9ce 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java @@ -213,6 +213,12 @@ class TextureViewRenderThread extends Thread implements TextureView.SurfaceTextu break; } + // (re-)Initialize EGL Surface if needed + if (eglHolder.eglSurface == EGL10.EGL_NO_SURFACE) { + recreateSurface = true; + break; + } + // Check if the size has changed if (sizeChanged) { recreateSurface = true; @@ -247,7 +253,14 @@ class TextureViewRenderThread extends Thread implements TextureView.SurfaceTextu // Initialize EGL if (initializeEGL) { eglHolder.prepare(); - eglHolder.createSurface(); + if (!eglHolder.createSurface()) { + synchronized (lock) { + // Cleanup the surface if one could not be created + // and wait for another to be ready. + destroySurface = true; + } + continue; + } mapRenderer.onSurfaceCreated(gl, eglHolder.eglConfig); mapRenderer.onSurfaceChanged(gl, w, h); continue; @@ -345,7 +358,7 @@ class TextureViewRenderThread extends Thread implements TextureView.SurfaceTextu // No texture view present eglConfig = null; eglContext = EGL10.EGL_NO_CONTEXT; - } else /*if (eglContext == EGL10.EGL_NO_CONTEXT)*/ { + } else if (eglContext == EGL10.EGL_NO_CONTEXT) { eglConfig = new EGLConfigChooser().chooseConfig(egl, eglDisplay); int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE}; eglContext = egl.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list); @@ -408,29 +421,33 @@ class TextureViewRenderThread extends Thread implements TextureView.SurfaceTextu } if (!egl.eglDestroySurface(eglDisplay, eglSurface)) { - Timber.e("Could not destroy egl surface. Display %s, Surface %s", eglDisplay, eglSurface); - throw new RuntimeException("eglDestroyContext: " + egl.eglGetError()); + Timber.w("Could not destroy egl surface. Display %s, Surface %s", eglDisplay, eglSurface); } + + eglSurface = EGL10.EGL_NO_SURFACE; } private void destroyContext() { - if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) { + if (eglContext == EGL10.EGL_NO_CONTEXT) { return; } if (!egl.eglDestroyContext(eglDisplay, eglContext)) { - Timber.e("Could not destroy egl context. Display %s, Context %s", eglDisplay, eglContext); - throw new RuntimeException("eglDestroyContext: " + egl.eglGetError()); + Timber.w("Could not destroy egl context. Display %s, Context %s", eglDisplay, eglContext); } + + eglContext = EGL10.EGL_NO_CONTEXT; } private void terminate() { - if (eglDisplay != EGL10.EGL_NO_DISPLAY) { - if (!egl.eglTerminate(eglDisplay)) { - Timber.w("Could not terminate egl. Display %s", eglDisplay); - } - eglDisplay = EGL10.EGL_NO_DISPLAY; + if (eglDisplay == EGL10.EGL_NO_DISPLAY) { + return; + } + + if (!egl.eglTerminate(eglDisplay)) { + Timber.w("Could not terminate egl. Display %s", eglDisplay); } + eglDisplay = EGL10.EGL_NO_DISPLAY; } void cleanup() { |