From 6d6f17ccfbd439d1eb6247b816c445de91852e98 Mon Sep 17 00:00:00 2001 From: Egor Date: Sun, 11 Feb 2018 10:58:51 -0800 Subject: Fixed Android crash when SwapBuffers() is called after Suspend() --- Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'Graphics/GraphicsEngineOpenGL') diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp index 09ed4f9f..0dce35d3 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp @@ -281,13 +281,19 @@ namespace Diligent void GLContext::SwapBuffers() { + if(surface_ == EGL_NO_SURFACE) + { + LOG_WARNING_MESSAGE("No EGL surface when swapping buffers. This happens when SwapBuffers() is called after Suspend(). The operation will be ignored."); + return; + } + bool b = eglSwapBuffers( display_, surface_ ); if( !b ) { EGLint err = eglGetError(); if( err == EGL_BAD_SURFACE ) { - //Recreate surface + LOG_INFO_MESSAGE("EGL surface has been lost. Attempting to recreate"); InitEGLSurface(); //return EGL_SUCCESS; //Still consider glContext is valid } @@ -329,13 +335,14 @@ namespace Diligent EGLint GLContext::Resume( ANativeWindow* window ) { + LOG_INFO_MESSAGE( "Resuming gl context\n" ); + if( egl_context_initialized_ == false ) { Init( window ); return EGL_SUCCESS; } - //Create surface window_ = window; surface_ = eglCreateWindowSurface( display_, config_, window_, NULL ); @@ -365,19 +372,21 @@ namespace Diligent else { //Recreate surface + LOG_INFO_MESSAGE( "Re-creating egl context and surface\n" ); Terminate(); InitEGLSurface(); InitEGLContext(); } return err; - } void GLContext::Suspend() { + LOG_INFO_MESSAGE( "Suspending gl context\n" ); if( surface_ != EGL_NO_SURFACE ) { + LOG_INFO_MESSAGE( "Destroying egl surface\n" ); eglDestroySurface( display_, surface_ ); surface_ = EGL_NO_SURFACE; } @@ -385,6 +394,7 @@ namespace Diligent bool GLContext::Invalidate() { + LOG_INFO_MESSAGE( "Invalidating gl context\n" ); Terminate(); egl_context_initialized_ = false; -- cgit v1.2.3