From 9c944731a2a3c48b347328f32dbee4514e8a972b Mon Sep 17 00:00:00 2001 From: Jordan Hollinger Date: Wed, 19 Nov 2014 11:23:06 -0800 Subject: [PATCH] Destory surface prior to destroying the view. #615 --- android/cpp/native_map_view.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/android/cpp/native_map_view.cpp b/android/cpp/native_map_view.cpp index 3997d9176..009e62b80 100644 --- a/android/cpp/native_map_view.cpp +++ b/android/cpp/native_map_view.cpp @@ -234,6 +234,14 @@ void NativeMapView::terminateDisplay() { mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::terminateDisplay"); if (display != EGL_NO_DISPLAY) { + // Destroy the surface first, if it still exists. This call needs a valid surface. + if (surface != EGL_NO_SURFACE) { + if (!eglDestroySurface(display, surface)) { + mbgl::Log::Error(mbgl::Event::OpenGL, "eglDestroySurface() returned error %d", eglGetError()); + } + surface = EGL_NO_SURFACE; + } + if (!eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) { mbgl::Log::Error(mbgl::Event::OpenGL, "eglMakeCurrent(EGL_NO_CONTEXT) returned error %d", @@ -541,7 +549,7 @@ void NativeMapView::loadExtensions() { void NativeMapView::stop() { mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::stop"); - if ((display != EGL_NO_DISPLAY) && (display != EGL_NO_CONTEXT)) { + if ((display != EGL_NO_DISPLAY) && (context != EGL_NO_CONTEXT)) { map.stop(); } } @@ -550,7 +558,7 @@ void NativeMapView::stop() { void NativeMapView::pause(bool wait_for_pause) { mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::pause %s", (wait_for_pause) ? "true" : "false"); - if ((display != EGL_NO_DISPLAY) && (display != EGL_NO_CONTEXT)) { + if ((display != EGL_NO_DISPLAY) && (context != EGL_NO_CONTEXT)) { map.pause(wait_for_pause); } }