cats-oss / android-gpuimage

Android filters based on OpenGL (idea from GPUImage for iOS)
8.99k stars 2.27k forks source link

NoSuchElementException when playing with Emboss filter #323

Open ankitbatra11 opened 8 years ago

ankitbatra11 commented 8 years ago

Hi, First of all thanks for this awesome work. I really appreciate it.

I would like to report an issue related to adjusting filter percentage (in my case EMBOSS). I am using GPUImageView in a fragment. I have set an image bitmap to the same. I applied EMBOSS filter to the image view and was adjusting it's percentage through a seek bar. While doing that I encountered below error:

idRuntime: FATAL EXCEPTION: GLThread 45348 java.util.NoSuchElementException at java.util.LinkedList.removeFirstImpl(LinkedList.java:689) at java.util.LinkedList.removeFirst(LinkedList.java:676) at jp.co.cyberagent.android.gpuimage.GPUImageFilter.runPendingOnDrawTasks(GPUImageFilter.java:134) at jp.co.cyberagent.android.gpuimage.GPUImageFilter.onDraw(GPUImageFilter.java:106) at jp.co.cyberagent.android.gpuimage.GPUImageFilterGroup.onDraw(GPUImageFilterGroup.java:201) at jp.co.cyberagent.android.gpuimage.GPUImageRenderer.onDrawFrame(GPUImageRenderer.java:120) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1535) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240) 10-13 09:38:35.898 2193-4036/? E/ConnectivityService: RemoteException caught trying to send a callback msg for NetworkRequest [ id=2250, legacyType=-1, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED] ] 10-13 09:38:37.778 13336-13336/? E/NEW_BHD: Battery Power Supply logging Daemon start!!!!! 10-13 09:38:37.779 13336-13336/? E/NEW_BHD: Cannot run on production devices! 10-13 09:38:42.801 13339-13339/? E/NEW_BHD: Battery Power Supply logging Daemon start!!!!!

ankitbatra11 commented 7 years ago

Seems like the crash is filter agnostic. I got another occurrence with a different filter type:

java.util.NoSuchElementException at java.util.LinkedList.removeFirstImpl(LinkedList.java:689) at java.util.LinkedList.removeFirst(LinkedList.java:676) at jp.co.cyberagent.android.gpuimage.GPUImageFilter.runPendingOnDrawTasks(GPUImageFilter.java:134) at jp.co.cyberagent.android.gpuimage.GPUImageFilter.onDraw(GPUImageFilter.java:106) at jp.co.cyberagent.android.gpuimage.GPUImageFilterGroup.onDraw(GPUImageFilterGroup.java:201) at jp.co.cyberagent.android.gpuimage.GPUImageRenderer.onDrawFrame(GPUImageRenderer.java:120) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1535) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

imandaliya commented 7 years ago

Same Issue, Application crashed many time because of this

Fatal Exception: java.util.NoSuchElementException at java.util.LinkedList.removeFirstImpl(LinkedList.java:689) at java.util.LinkedList.removeFirst(LinkedList.java:676) at com.ist.quotescreator.gpu.GPUImageFilter.runPendingOnDrawTasks(Unknown Source) at com.ist.quotescreator.gpu.GPUImageFilter.onInit(Unknown Source) at com.ist.quotescreator.gpu.GPUImageFilterGroup.addFilter(Unknown Source) at com.ist.quotescreator.gpu.GPUImageRenderer.onDrawFrame(Unknown Source) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1531) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)

mhousser commented 7 years ago

I get this all the time.

In fact, I had to subclass GPUImageFilterGroup in production and wrap a try-catch around super.onDraw(..) because this NoSuchElementException keeps popping up every now and then. Once it happens, it won't go away until you kill everything and re-open the screen that uses GPUImage.

It's this code:

        while (!mRunOnDraw.isEmpty()) {
            mRunOnDraw.removeFirst().run();
        }

Funny enough, isEmpty() will return false if size() > 0.. but then removeFirst() throws an exception if the first item itself is null. There's something funny going on here.. there IS an item in the LinkedList, but it's a null item... how are we getting into this state every now and then?

HungTDO commented 7 years ago

I've got same error:

java.util.NoSuchElementException: 
  at java.util.LinkedList.removeFirstImpl(LinkedList.java:689)
  at java.util.LinkedList.removeFirst(LinkedList.java:676)
  at jp.co.cyberagent.android.gpuimage.GPUImageFilter.runPendingOnDrawTasks(GPUImageFilter.java:134)
  at jp.co.cyberagent.android.gpuimage.GPUImageFilter.onDraw(GPUImageFilter.java:106)
  at jp.co.cyberagent.android.gpuimage.GPUImageRenderer.onDrawFrame(GPUImageRenderer.java:120)
  at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1531)
  at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)

This's cause (in lib's code):

    private final LinkedList<Runnable> mRunOnDraw;
    protected void runPendingOnDrawTasks() {
        while (!mRunOnDraw.isEmpty()) {
            mRunOnDraw.removeFirst().run();
        }
    }

I think there is a problem of asynchrony in this case!

Related method:

    protected void runOnDraw(final Runnable runnable) {
        synchronized (mRunOnDraw) {
            mRunOnDraw.addLast(runnable);
        }
    }

plz. Fix it.

HungTDO commented 6 years ago

Thanks to @chapj2001