Skip to content

Commit 6d6f17c

Browse files
Fixed Android crash when SwapBuffers() is called after Suspend()
1 parent ea7e607 commit 6d6f17c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,19 @@ namespace Diligent
281281

282282
void GLContext::SwapBuffers()
283283
{
284+
if(surface_ == EGL_NO_SURFACE)
285+
{
286+
LOG_WARNING_MESSAGE("No EGL surface when swapping buffers. This happens when SwapBuffers() is called after Suspend(). The operation will be ignored.");
287+
return;
288+
}
289+
284290
bool b = eglSwapBuffers( display_, surface_ );
285291
if( !b )
286292
{
287293
EGLint err = eglGetError();
288294
if( err == EGL_BAD_SURFACE )
289295
{
290-
//Recreate surface
296+
LOG_INFO_MESSAGE("EGL surface has been lost. Attempting to recreate");
291297
InitEGLSurface();
292298
//return EGL_SUCCESS; //Still consider glContext is valid
293299
}
@@ -329,13 +335,14 @@ namespace Diligent
329335

330336
EGLint GLContext::Resume( ANativeWindow* window )
331337
{
338+
LOG_INFO_MESSAGE( "Resuming gl context\n" );
339+
332340
if( egl_context_initialized_ == false )
333341
{
334342
Init( window );
335343
return EGL_SUCCESS;
336344
}
337345

338-
339346
//Create surface
340347
window_ = window;
341348
surface_ = eglCreateWindowSurface( display_, config_, window_, NULL );
@@ -365,26 +372,29 @@ namespace Diligent
365372
else
366373
{
367374
//Recreate surface
375+
LOG_INFO_MESSAGE( "Re-creating egl context and surface\n" );
368376
Terminate();
369377
InitEGLSurface();
370378
InitEGLContext();
371379
}
372380

373381
return err;
374-
375382
}
376383

377384
void GLContext::Suspend()
378385
{
386+
LOG_INFO_MESSAGE( "Suspending gl context\n" );
379387
if( surface_ != EGL_NO_SURFACE )
380388
{
389+
LOG_INFO_MESSAGE( "Destroying egl surface\n" );
381390
eglDestroySurface( display_, surface_ );
382391
surface_ = EGL_NO_SURFACE;
383392
}
384393
}
385394

386395
bool GLContext::Invalidate()
387396
{
397+
LOG_INFO_MESSAGE( "Invalidating gl context\n" );
388398
Terminate();
389399

390400
egl_context_initialized_ = false;

0 commit comments

Comments
 (0)