From db043f324f8783e535d346ccd166a6bae19f658f Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Fri, 20 Jan 2012 03:11:35 +0300 Subject: [PATCH] [android] Avoid using lost OpenGL context when cleaning up resources --- android/jni/com/mapswithme/maps/VideoTimer.cpp | 10 ++++++++++ .../src/com/mapswithme/maps/SmartGLSurfaceView.java | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/android/jni/com/mapswithme/maps/VideoTimer.cpp b/android/jni/com/mapswithme/maps/VideoTimer.cpp index 96b63b4f7d..d3527dee18 100644 --- a/android/jni/com/mapswithme/maps/VideoTimer.cpp +++ b/android/jni/com/mapswithme/maps/VideoTimer.cpp @@ -6,6 +6,14 @@ static jobject g_smartGLSurfaceView = 0; static jmethodID g_requestRenderMethodID; +// @TODO Hack to avoid opengl calls when surface is destroyed +namespace yg +{ +namespace gl +{ + extern bool g_doDeleteOnDestroy; +} +} extern "C" { @@ -14,6 +22,7 @@ Java_com_mapswithme_maps_SmartGLSurfaceView_nativeBind(JNIEnv * env, jobject thi { if (isBound) { + yg::gl::g_doDeleteOnDestroy = true; g_requestRenderMethodID = jni::GetJavaMethodID(env, thiz, "requestRender", "()V"); ASSERT(g_requestRenderMethodID, ("Can't find method void com/mapswithme/maps/SmartGLSurfaceView.requestRender()")); @@ -21,6 +30,7 @@ Java_com_mapswithme_maps_SmartGLSurfaceView_nativeBind(JNIEnv * env, jobject thi } else { + yg::gl::g_doDeleteOnDestroy = false; jobject refToDelete = g_smartGLSurfaceView; g_smartGLSurfaceView = 0; env->DeleteGlobalRef(refToDelete); diff --git a/android/src/com/mapswithme/maps/SmartGLSurfaceView.java b/android/src/com/mapswithme/maps/SmartGLSurfaceView.java index a738880db2..59f521a585 100644 --- a/android/src/com/mapswithme/maps/SmartGLSurfaceView.java +++ b/android/src/com/mapswithme/maps/SmartGLSurfaceView.java @@ -73,11 +73,10 @@ public class SmartGLSurfaceView extends GLSurfaceView public void surfaceDestroyed (SurfaceHolder holder) { Log.d(TAG, "surfaceDestroyed"); + nativeBind(false); m_renderer.m_isBaseSurfaceReady = false; m_renderer.m_isLocalSurfaceReady = false; super.surfaceDestroyed(holder); - queueEvent(m_unloadResources); - nativeBind(false); } @Override @@ -93,14 +92,15 @@ public class SmartGLSurfaceView extends GLSurfaceView public void onPause() { m_renderer.m_isActive = false; - super.onPause(); queueEvent(m_unloadResources); + super.onPause(); } // Should be called from parent activity public void onStop() { - queueEvent(m_unloadResources); + // To avoid releasing OpenGL resources - we've already lost context here + nativeBind(false); } @Override