summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2021-10-02 00:00:43 +0200
committerStanislaw Halik <sthalik@misaki.pl>2021-10-02 00:01:38 +0200
commit16497b0362244407a139479b6e15834cf709779c (patch)
treef30648421d0ec4978a9d5242730cb9930c4a5150
parenta42a6ec0d7f99de0aabf9c9732303ded426e843f (diff)
tracker/pt: fix rare crash due to QProcess use across threads
This was caused by QProcess in video/ps3eye getting created from the UI thread, then recreated on the Point Tracker's thread.
-rw-r--r--tracker-pt/ftnoir_tracker_pt.cpp37
-rw-r--r--tracker-pt/ftnoir_tracker_pt.h2
2 files changed, 20 insertions, 19 deletions
diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp
index 93074883..b996448b 100644
--- a/tracker-pt/ftnoir_tracker_pt.cpp
+++ b/tracker-pt/ftnoir_tracker_pt.cpp
@@ -28,16 +28,12 @@ Tracker_PT::Tracker_PT(pointer<pt_runtime_traits> const& traits) :
traits { traits },
s { traits->get_module_name() },
point_extractor { traits->make_point_extractor() },
- camera { traits->make_camera() },
frame { traits->make_frame() }
{
opencv_init();
- connect(s.b.get(), &bundle_::saving, this, &Tracker_PT::maybe_reopen_camera, Qt::DirectConnection);
- connect(s.b.get(), &bundle_::reloading, this, &Tracker_PT::maybe_reopen_camera, Qt::DirectConnection);
-
+ connect(s.b.get(), &bundle_::saving, this, [this]{ reopen_camera_flag = true; }, Qt::DirectConnection);
connect(&s.fov, value_::value_changed<int>(), this, &Tracker_PT::set_fov, Qt::DirectConnection);
- set_fov(s.fov);
}
Tracker_PT::~Tracker_PT()
@@ -53,11 +49,21 @@ void Tracker_PT::run()
{
portable::set_curthread_name("tracker/pt");
- if (!maybe_reopen_camera())
- return;
-
while(!isInterruptionRequested())
{
+ if (reopen_camera_flag)
+ {
+ reopen_camera_flag = false;
+ if (camera)
+ camera->stop();
+ camera = traits->make_camera();
+ set_fov(s.fov);
+ {
+ QMutexLocker l(&camera_mtx);
+ (void)camera->start(s);
+ }
+ }
+
pt_camera_info info;
bool new_frame = false;
@@ -111,17 +117,11 @@ void Tracker_PT::run()
}
}
-bool Tracker_PT::maybe_reopen_camera()
-{
- QMutexLocker l(&camera_mtx);
-
- return camera->start(s);
-}
-
void Tracker_PT::set_fov(int value)
{
QMutexLocker l(&camera_mtx);
- camera->set_fov(value);
+ if (camera)
+ camera->set_fov(value);
}
module_status Tracker_PT::start_tracker(QFrame* video_frame)
@@ -206,9 +206,10 @@ int Tracker_PT::get_n_points()
bool Tracker_PT::get_cam_info(pt_camera_info& info)
{
QMutexLocker l(&camera_mtx);
- bool ret;
+ bool ret = false;
- std::tie(ret, info) = camera->get_info();
+ if (camera)
+ std::tie(ret, info) = camera->get_info();
return ret;
}
diff --git a/tracker-pt/ftnoir_tracker_pt.h b/tracker-pt/ftnoir_tracker_pt.h
index fa3d94ad..50e51405 100644
--- a/tracker-pt/ftnoir_tracker_pt.h
+++ b/tracker-pt/ftnoir_tracker_pt.h
@@ -50,7 +50,6 @@ struct Tracker_PT : QThread, ITracker
private:
void run() override;
- bool maybe_reopen_camera();
void set_fov(int value);
pointer<pt_runtime_traits> traits;
@@ -74,6 +73,7 @@ private:
std::atomic<unsigned> point_count { 0 };
std::atomic<bool> ever_success = false;
+ std::atomic<bool> reopen_camera_flag = true;
mutable QMutex center_lock, data_lock;
point_filter filter{s};
};