From a16f2c07ea7301ed1b82b9039ea7db7c025054ff Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 1 Sep 2015 19:51:53 +0100 Subject: [PATCH] Fix crash on cancellation of encodes during check of image data; allow cancellation during this time (#679). --- ChangeLog | 3 +++ src/lib/job.cc | 12 +++++++----- src/lib/job.h | 1 + src/lib/writer.cc | 9 +++++++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 98e349d09..d7d7e2ca5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2015-09-01 Carl Hetherington + * Allow cancellation of transcodes during the + checking of existing frames (#679). + * Version 2.1.49 released. 2015-08-31 Carl Hetherington diff --git a/src/lib/job.cc b/src/lib/job.cc index d9715aa18..87e4fb3d3 100644 --- a/src/lib/job.cc +++ b/src/lib/job.cc @@ -247,6 +247,12 @@ Job::set_progress (float p, bool force) return; } + set_progress_common (p); +} + +void +Job::set_progress_common (optional p) +{ boost::mutex::scoped_lock lm (_progress_mutex); _progress = p; boost::this_thread::interruption_point (); @@ -315,11 +321,7 @@ Job::set_error (string s, string d) void Job::set_progress_unknown () { - boost::mutex::scoped_lock lm (_progress_mutex); - _progress.reset (); - lm.unlock (); - - emit (boost::bind (boost::ref (Progress))); + set_progress_common (optional ()); } /** @return Human-readable status of this job */ diff --git a/src/lib/job.h b/src/lib/job.h index 06a341f40..4e52e76a1 100644 --- a/src/lib/job.h +++ b/src/lib/job.h @@ -106,6 +106,7 @@ protected: private: void run_wrapper (); + void set_progress_common (boost::optional p); boost::thread* _thread; diff --git a/src/lib/writer.cc b/src/lib/writer.cc index 58b2b8a91..9c4a194e8 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -147,9 +147,14 @@ Writer::Writer (shared_ptr film, weak_ptr j) throw InvalidSignerError (); } - _thread = new boost::thread (boost::bind (&Writer::thread, this)); - job->sub (_("Encoding image data")); + + /* Do this last; if something after this line were to throw an exception + (say if Job::sub was interrupted by cancel) this thread would never + get properly cleaned up but the Writer object would go away underneath + it. + */ + _thread = new boost::thread (boost::bind (&Writer::thread, this)); } Writer::~Writer () -- 2.30.2