fix Android camera datarace (mCameraFrameReady)
authorAlexander Alekhin <alexander.alekhin@itseez.com>
Tue, 22 Sep 2015 12:35:25 +0000 (15:35 +0300)
committerAlexander Alekhin <alexander.alekhin@itseez.com>
Tue, 22 Sep 2015 14:03:09 +0000 (17:03 +0300)
modules/java/generator/src/java/android+JavaCameraView.java

index fca29db..f4405c3 100644 (file)
@@ -328,6 +328,7 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
         @Override
         public void run() {
             do {
+                boolean hasFrame = false;
                 synchronized (JavaCameraView.this) {
                     try {
                         while (!mCameraFrameReady && !mStopThread) {
@@ -337,11 +338,14 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
                         e.printStackTrace();
                     }
                     if (mCameraFrameReady)
+                    {
                         mChainIdx = 1 - mChainIdx;
+                        mCameraFrameReady = false;
+                        hasFrame = true;
+                    }
                 }
 
-                if (!mStopThread && mCameraFrameReady) {
-                    mCameraFrameReady = false;
+                if (!mStopThread && hasFrame) {
                     if (!mFrameChain[1 - mChainIdx].empty())
                         deliverAndDrawFrame(mCameraFrame[1 - mChainIdx]);
                 }