E/OpenGLRenderer: Unable to match the desired swap behavior

I get this log message when I run my Android Studio app. How do I fix this problem?

Thank you…

1 Like

Hi. I have the same problem. Did you find any solution? Thanks.

If you check:

you’ll see there’s a Surface option that can be set via eglSurfaceAttrib() called:

  • EGL_SWAP_BEHAVIOR

which has the following possible values:

  • EGL_BUFFER_PRESERVED - indicates that color buffer contents are unaffected, while
  • EGL_BUFFER_DESTROYED - indicates that color buffer contents may be destroyed or changed by the operation.

This setting pertains to the COLOR buffer of an EGL surface such as a window.

You’re apparently running an application that’s requesting a specific swap buffers behavior for a surface (probably EGL_BUFFER_PRESERVED) that the graphics driver, in its current configuration at least, does not support. So it’s telling you that.

If this was your application, the fix is don’t depend on this swap behavior, because in some circumstances you won’t get it. Better to render to an offscreen FBO backed by textures and/or renderbuffers, where you have control of the contents of these FBO buffers from frame-to-frame.

Again if this was your application, prior to creating your EGL surface, you could look for an EGLConfig which supports the EGL_SWAP_BEHAVIOR == EGL_BUFFER_PRESERVED behavior. You do this by specifying EGL_SWAP_BEHAVIOR_PRESERVED_BIT in the EGL_SURFACE_TYPE value when choosing the desired EGLConfig. That said, if you don’t find one, you can’t get EGL_BUFFER_PRESERVED behavior via an EGL surface on that graphics driver. Again, the solution is to just render to an FBO where you have full control of frame-to-frame content persistence and not depend on the persistence behavior of the system framebuffer.

1 Like

Thanks for your reply. It is my application. But it is a very plain application, with no EGL at all. I searched the whole source code for the “EGL” string and it is not present at all.

It seems all other applications on my phone (Pixel 5) produce the same error, so I guess it is not my fault.

I will stop trying to fix this, since my app is working anyway.

So while your app may not be directly using EGL, it is most likely using it indirectly through whatever libraries and layers you are using to provide window and graphics rendering capability for your application.

Ah! Here you go:

Notice the error message in that last code fragment. Look familiar?:

"Unable to match the desired swap behavior."

Assuming this is the source of your message, you can observe a few things:

  • This uses EGL
  • It also uses OpenGL ES

My guess is you’re using EGL / OpenGL ES via Skia, either directly or indirectly.

Skia:

1 Like