Fix crash on resume in face detection sample
authorAndrey Kamaev <andrey.kamaev@itseez.com>
Thu, 23 Aug 2012 12:02:33 +0000 (16:02 +0400)
committerAndrey Kamaev <andrey.kamaev@itseez.com>
Fri, 24 Aug 2012 12:24:53 +0000 (16:24 +0400)
samples/android/face-detection/jni/DetectionBasedTracker_jni.cpp
samples/android/face-detection/src/org/opencv/samples/fd/SampleCvViewBase.java

index 67171c2..33ee8e7 100644 (file)
@@ -68,6 +68,7 @@ struct DetectorAgregator
 JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject
 (JNIEnv * jenv, jclass, jstring jFileName, jint faceSize)
 {
+    LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject enter");
     const char* jnamestr = jenv->GetStringUTFChars(jFileName, NULL);
     string stdFileName(jnamestr);
     jlong result = 0;
@@ -101,6 +102,7 @@ JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeC
         return 0;
     }
 
+    LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject exit");
     return result;
 }
 
@@ -111,8 +113,11 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDe
 
     try
     {
-        ((DetectorAgregator*)thiz)->tracker->stop();
-        delete (DetectorAgregator*)thiz;
+        if(thiz != 0)
+        {
+            ((DetectorAgregator*)thiz)->tracker->stop();
+            delete (DetectorAgregator*)thiz;
+        }
     }
     catch(cv::Exception e)
     {
@@ -128,6 +133,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDe
         jclass je = jenv->FindClass("java/lang/Exception");
         jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject(...)}");
     }
+    LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject exit");
 }
 
 JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart
@@ -153,6 +159,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt
         jclass je = jenv->FindClass("java/lang/Exception");
         jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart(...)}");
     }
+    LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart exit");
 }
 
 JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop
@@ -178,6 +185,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt
         jclass je = jenv->FindClass("java/lang/Exception");
         jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop(...)}");
     }
+    LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop exit");
 }
 
 JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize
index 0e99076..f24f602 100644 (file)
@@ -34,8 +34,8 @@ public abstract class SampleCvViewBase extends SurfaceView implements SurfaceHol
             releaseCamera();
             mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID);
             if (!mCamera.isOpened()) {
-                releaseCamera();
                 Log.e(TAG, "Failed to open native camera");
+                releaseCamera();
                 return false;
             }
         }
@@ -92,6 +92,7 @@ public abstract class SampleCvViewBase extends SurfaceView implements SurfaceHol
     public void surfaceDestroyed(SurfaceHolder holder) {
         Log.i(TAG, "surfaceDestroyed");
         releaseCamera();
+        Log.i(TAG, "surfaceDestroyed2");
     }
 
     protected abstract Bitmap processFrame(VideoCapture capture);