From eb2e061e3f4ef433771f0b2c2b577cc5a956fd33 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 22 Sep 2015 15:35:25 +0300 Subject: [PATCH] fix Android camera datarace (mCameraFrameReady) --- .../java/generator/src/java/android+JavaCameraView.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/java/generator/src/java/android+JavaCameraView.java b/modules/java/generator/src/java/android+JavaCameraView.java index fca29db6eb..f4405c3501 100644 --- a/modules/java/generator/src/java/android+JavaCameraView.java +++ b/modules/java/generator/src/java/android+JavaCameraView.java @@ -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]); }