Fix LTC encoder removal
authorRobin Gareus <robin@gareus.org>
Tue, 1 Aug 2017 15:48:42 +0000 (17:48 +0200)
committerRobin Gareus <robin@gareus.org>
Tue, 1 Aug 2017 15:48:42 +0000 (17:48 +0200)
Fixed a crash if an x-run or graph-reorder happens after the LTC encoder
has been destroyed (possible at session-close or after disabling
the encoder).  This also fixes duplicate callbacks in case the
encoder was re-enabled times in an active session.

libs/ardour/ardour/session.h
libs/ardour/session_ltc.cc

index 96adcf0981b48764595c0b527cd31a67f536b45a..1123abd02ebae48e1d0c71ed8313f7e833edd3b1 100644 (file)
@@ -1677,6 +1677,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        void ltc_tx_recalculate_position();
        void ltc_tx_parse_offset();
        void ltc_tx_send_time_code_for_cycle (framepos_t, framepos_t, double, double, pframes_t nframes);
+       PBD::ScopedConnectionList ltc_tx_connections;
+
 
        void reset_record_status ();
 
index 51a39d0677c2f6169320aa84454e3b681baa8aaf..87fd47e70ea9543a8ab1402d71d9d4361b932f27 100644 (file)
@@ -84,8 +84,8 @@ Session::ltc_tx_initialize()
        ltc_prev_cycle = -1;
        ltc_tx_reset();
        ltc_tx_resync_latency();
-       Xrun.connect_same_thread (*this, boost::bind (&Session::ltc_tx_reset, this));
-       engine().GraphReordered.connect_same_thread (*this, boost::bind (&Session::ltc_tx_resync_latency, this));
+       Xrun.connect_same_thread (ltc_tx_connections, boost::bind (&Session::ltc_tx_reset, this));
+       engine().GraphReordered.connect_same_thread (ltc_tx_connections, boost::bind (&Session::ltc_tx_resync_latency, this));
        restarting = false;
 }
 
@@ -97,6 +97,7 @@ Session::ltc_tx_cleanup()
        ltc_enc_buf = NULL;
        ltc_encoder_free(ltc_encoder);
        ltc_encoder = NULL;
+       ltc_tx_connections.drop_connections ();
 }
 
 void
@@ -115,6 +116,7 @@ void
 Session::ltc_tx_reset()
 {
        DEBUG_TRACE (DEBUG::LTC, "LTC TX reset\n");
+       assert (ltc_encoder);
        ltc_enc_pos = -9999; // force re-start
        ltc_buf_len = 0;
        ltc_buf_off = 0;