Allow _film to be 0.
[dcpomatic.git] / src / lib / job.cc
index 37bf462fca0a3b1ffb65063a008f9b572df18982..91581eb49550db343718606c5ede43ab249f6774 100644 (file)
@@ -31,6 +31,7 @@
 #include <dcp/exceptions.h>
 #include <boost/thread.hpp>
 #include <boost/filesystem.hpp>
+#include <iostream>
 
 #include "i18n.h"
 
@@ -43,6 +44,7 @@ using boost::function;
 
 #define LOG_ERROR_NC(...) _film->log()->log (__VA_ARGS__, Log::TYPE_ERROR);
 
+/** @param film Associated film, or 0 */
 Job::Job (shared_ptr<const Film> film)
        : _film (film)
        , _thread (0)
@@ -58,6 +60,7 @@ Job::~Job ()
 {
        if (_thread) {
                _thread->interrupt ();
+               DCPOMATIC_ASSERT (_thread->joinable ());
                _thread->join ();
        }
 
@@ -132,7 +135,7 @@ Job::run_wrapper ()
 
        } catch (std::bad_alloc& e) {
 
-               set_error (_("Out of memory"), _("There was not enough memory to do this."));
+               set_error (_("Out of memory"), _("There was not enough memory to do this.  If you are running a 32-bit operating system try reducing the number of encoding threads in the General tab of Preferences."));
                set_progress (1);
                set_state (FINISHED_ERROR);
 
@@ -322,7 +325,9 @@ Job::set_error (string s, string d)
        LOG_ERROR_NC (s);
        LOG_ERROR_NC (d);
 
-       _film->log()->log (String::compose ("Error in job: %1 (%2)", s, d), Log::TYPE_ERROR);
+       if (_film) {
+               _film->log()->log (String::compose ("Error in job: %1 (%2)", s, d), Log::TYPE_ERROR);
+       }
        boost::mutex::scoped_lock lm (_state_mutex);
        _error_summary = s;
        _error_details = d;
@@ -415,7 +420,10 @@ Job::cancel ()
        }
 
        _thread->interrupt ();
+       DCPOMATIC_ASSERT (_thread->joinable ());
        _thread->join ();
+       delete _thread;
+       _thread = 0;
 }
 
 void
@@ -446,4 +454,3 @@ Job::when_finished (boost::signals2::connection& connection, function<void()> fi
                connection = Finished.connect (finished);
        }
 }
-