From cdbe9e8ea3283dde4667098e8b35f09b94cbcfc4 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 7 Jul 2015 11:49:12 +0200 Subject: camera dialog: don't crash due to race condition We have no idea when the capture can be closed, so wait for three seconds instead. --- opentrack/opencv-camera-dialog.hpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/opentrack/opencv-camera-dialog.hpp b/opentrack/opencv-camera-dialog.hpp index 3b700a70..6218f125 100644 --- a/opentrack/opencv-camera-dialog.hpp +++ b/opentrack/opencv-camera-dialog.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -9,6 +10,14 @@ template class camera_dialog { cv::VideoCapture fake_capture; + QTimer t; + +private: + void delete_capture() + { + fake_capture.open(""); + } + public: void open_camera_settings(cv::VideoCapture* cap, const QString& camera_name, QMutex* camera_mtx) { @@ -23,10 +32,20 @@ public: } } + if (t.isActive()) + return; + + // don't hog the camera capture + if (!t.isSingleShot()) + QObject::connect(&t, &QTimer::timeout, [&]() -> void { delete_capture(); }); + + t.setSingleShot(true); + t.setInterval(3000); + fake_capture = cv::VideoCapture(camera_name_to_index(camera_name)); fake_capture.set(cv::CAP_PROP_SETTINGS, 1); - // don't hog the camera capture - fake_capture.open(""); + // HACK: we're not notified when it's safe to close the capture + t.start(); } }; -- cgit v1.2.3