Fix crash on cancellation of encodes during check of image data; allow cancellation...
authorCarl Hetherington <cth@carlh.net>
Tue, 1 Sep 2015 18:51:53 +0000 (19:51 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 1 Sep 2015 18:51:53 +0000 (19:51 +0100)
ChangeLog
src/lib/job.cc
src/lib/job.h
src/lib/writer.cc

index 98e349d099a5f762b4dc15facad4faec01ce666f..d7d7e2ca526b52747a43e6ab073c14e4f7a1c199 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2015-09-01  Carl Hetherington  <cth@carlh.net>
 
+       * Allow cancellation of transcodes during the
+       checking of existing frames (#679).
+
        * Version 2.1.49 released.
 
 2015-08-31  Carl Hetherington  <cth@carlh.net>
index d9715aa18535603d6040b6c8287b2788e385f086..87e4fb3d370c783a99802eaf8dcc09e5e3a2af1c 100644 (file)
@@ -247,6 +247,12 @@ Job::set_progress (float p, bool force)
                return;
        }
 
+       set_progress_common (p);
+}
+
+void
+Job::set_progress_common (optional<float> 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<float> ());
 }
 
 /** @return Human-readable status of this job */
index 06a341f40d6808581d4bcf44ed3f2805f15285d1..4e52e76a1cf6d845741f502882e0792ca5c43ec2 100644 (file)
@@ -106,6 +106,7 @@ protected:
 private:
 
        void run_wrapper ();
+       void set_progress_common (boost::optional<float> p);
 
        boost::thread* _thread;
 
index 58b2b8a91ae866034e7badad4ea51b97b906c89f..9c4a194e806f02677f4caf4d76155aa2c79e0b09 100644 (file)
@@ -147,9 +147,14 @@ Writer::Writer (shared_ptr<const Film> film, weak_ptr<Job> 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 ()