Skip to content

Commit

Permalink
Replace semaphore with wait()/notify() to prevent reaching code befor…
Browse files Browse the repository at this point in the history
…e filter was destroyed (destroying the filter and particularly its buffer later results in NPE)
  • Loading branch information
ubuntudroid committed Jul 8, 2013
1 parent 88d8c99 commit 0c43346
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions library/src/jp/co/cyberagent/android/gpuimage/GPUImage.java
Expand Up @@ -249,21 +249,23 @@ public Bitmap getBitmapWithFilterApplied() {
public Bitmap getBitmapWithFilterApplied(final Bitmap bitmap) {
if (mGlSurfaceView != null) {
mRenderer.deleteImage();
final Semaphore lock = new Semaphore(0);
mRenderer.runOnDraw(new Runnable() {

@Override
public void run() {
mFilter.destroy();
lock.release();
synchronized(mFilter) {
mFilter.destroy();
mFilter.notify();
}
}
});
requestRender();

try {
lock.acquire();
} catch (InterruptedException e) {
e.printStackTrace();
synchronized(mFilter) {
try {
mFilter.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

Expand Down

0 comments on commit 0c43346

Please sign in to comment.