From c78142acb016a11385bb0a82c66bdc66fd7b7be8 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 25 Feb 2014 11:50:55 +0400 Subject: [PATCH] Bug #3391 org.opencv.android.NativeCameraView crashes after latest OpenCV Manager update fixed. The crash was cased by massive Mat objects leak in NativeCameraView class. --- .../src/java/android+NativeCameraView.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/java/generator/src/java/android+NativeCameraView.java b/modules/java/generator/src/java/android+NativeCameraView.java index 62d0775801..8035d04377 100644 --- a/modules/java/generator/src/java/android+NativeCameraView.java +++ b/modules/java/generator/src/java/android+NativeCameraView.java @@ -22,6 +22,7 @@ public class NativeCameraView extends CameraBridgeViewBase { private Thread mThread; protected VideoCapture mCamera; + protected NativeCameraFrame mFrame; public NativeCameraView(Context context, int cameraId) { super(context, cameraId); @@ -97,6 +98,8 @@ public class NativeCameraView extends CameraBridgeViewBase { if (mCamera.isOpened() == false) return false; + mFrame = new NativeCameraFrame(mCamera); + java.util.List sizes = mCamera.getSupportedPreviewSizes(); /* Select the size that fits surface considering maximum size allowed */ @@ -127,9 +130,8 @@ public class NativeCameraView extends CameraBridgeViewBase { private void releaseCamera() { synchronized (this) { - if (mCamera != null) { - mCamera.release(); - } + if (mFrame != null) mFrame.release(); + if (mCamera != null) mCamera.release(); } } @@ -153,6 +155,11 @@ public class NativeCameraView extends CameraBridgeViewBase { mRgba = new Mat(); } + public void release() { + if (mGray != null) mGray.release(); + if (mRgba != null) mRgba.release(); + } + private VideoCapture mCapture; private Mat mRgba; private Mat mGray; @@ -167,7 +174,7 @@ public class NativeCameraView extends CameraBridgeViewBase { break; } - deliverAndDrawFrame(new NativeCameraFrame(mCamera)); + deliverAndDrawFrame(mFrame); } while (!mStopThread); }