EGL_BAD_MATCH when rendering to GLSurfaceView on some cameras
In my app, I often find that GPUImage filters apply cleanly to the GLSurfaceView until I attempt to take a picture. In the picture callback, I call GPUImage.getBitmapWithFilterApplied() and get back either a black image or an image with only the filter colors applied to a black image. Whenever this happens, libEGL errors appear like these:
E/libEGL﹕ eglMakeCurrent:895 error 3009 (EGL_BAD_MATCH) E/libEGL﹕ call to OpenGL ES API with no current context (logged once per thread) E/libEGL﹕ eglDestroySurface:638 error 300d (EGL_BAD_SURFACE)
When I dig into the getBitmapWithFilterApplied function, I can see that the bitmap passed in is correct, but the bitmap in the PixelBuffer is blank/transparent. On StackOverflow, it seems these libEGL errors occur mostly when there is one of:
- A mismatch of the OpenGL ES API version
- A mismatch of the requested target surface type
- The requested color bit depth cannot be rendered on the surface view
In many cases, I find the same Android-GPUImage code works fine for the front camera, but I get EGL errors and a blank bitmap from the rear camera on the same device. This leads me to believe that the GPUImage.setGLSurfaceView() code might poorly handle certain cameras.
Two cameras which exhibit this problem for me are the Samsung Galaxy S4 and Moto X 2014 back facing cameras.
Note that this problem does not occur when the devices are showing filters applied to the camera previews-- only when I call getBitmapWithFilterApplied() on the saved camera image.
i encounter the same problem as well. Do you have any update for this bro? Thx.
I forked the library to try potential fixes. The most likely answer was to experiment with a custom GLSurfaceView EGLConfigChooser, but I haven't had much luck with this yet. I'm still investigating.
I'm about 80% sure the problem originates in the PixelBuffer class. The eglMakeCurrent errors seem to come from there, there is very little error checking, and the comments suggest best guess attempts at a safe OpenGL config. I'll see what I can learn today.
I finally have my answer. The issue originates from passing an image larger than the screen into GPUImage.setImage(). On certain Adreno and Tegra GPUs (but not my Nexus 6), passing a large bitmap causes the above error and OpenGL crash. Images larger than the screen would be a common occurrence when applying a filter to an image saved from the back-facing camera. It's not at all unusual to display the saved image on the screen immediately after taking the picture and even offer to let the user pinch to zoom. Downscaling the image is a workaround.
Since the library doesn't check for EGL errors, we only see the above error. eglMakeCurrent() is not the first call to fail, but it is the first to display an error without checking eglGetError().
I have same issue any one have solution for that? @wasabeef @itome @colintheshots