opencv / opencv

Open Source Computer Vision Library

Home Page:https://opencv.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cocoa Application VideoCapture crashes on release() using AVFoundation

aprowe opened this issue · comments

System information (version)
  • OpenCV => Dec 7th HEAD (2341222)
  • Operating System / Platform => Mac 10.11 / 10.12
  • Compiler => Xcode
Detailed description

We are trying to use an AVFoundation build of opencv_videoio in our macOS app.
It is able to open the webcam and read from it, but once release is called, a EXC_BAD_ACCESS Error is thrown. Here are stack traces caught by Zombies. I wasn't sure exactly what is relevant in the zombie report. Here's a screenshot.

screen shot 2016-12-09 at 3 16 07 pm

Stepping through the code, It successfully turns the camera off, exits release(), and continue program flow, and another thread crashes the program each time.

It does NOT crash on a blank c++ command line project, only happens in a cocoa app.

We have tried running both on Sierra and El Capitan.
We chose to use AVFoundation to support Sierra, and chose to not use FFMpeg. Are there any other build options to consider?

Steps to reproduce

Build openCV with

WITH_AVFOUNDATION=YES
WITH_FFMPEG=NO
WITH_QT=NO
WITH_QUICKTIME=NO

Create an empty Cocoa Project,
and in ApplicationDidFinishLaunching put basic VideoIO capture calls in

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  cv::VideoCapture cap(0);
  cap.release();
}

In cap_avfoundation_mac.mm, function CvCaptureCAM::stopCaptureDevice, comment this line [mCaptureDevice release];

This fixed it, thank you!