forked from organicmaps/organicmaps-tmp
[android] Avoid using lost OpenGL context when cleaning up resources
This commit is contained in:
parent
e8f3d89c73
commit
db043f324f
2 changed files with 14 additions and 4 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue