FP8: Clear input port on close. Fixes crash when switching snapshots
authorRobin Gareus <robin@gareus.org>
Sat, 1 Jul 2017 00:22:44 +0000 (02:22 +0200)
committerRobin Gareus <robin@gareus.org>
Sat, 1 Jul 2017 00:55:47 +0000 (02:55 +0200)
The midi_input_handler for the AsyncMIDIPort is connected to the
main event-loop. Events may still be delivered after the surface was
destroyed.

That by itself is not harmful, unless a given message produces a reply:
The _output_port is already gone, FaderPort8::tx_midi crashes.

libs/surfaces/faderport8/faderport8.cc

index 923f635324f0ae757eaf5e9f4410e94fde8f6728..50d8a213b0bc0de4f7978a75a77dd1275a24fe76 100644 (file)
@@ -150,6 +150,9 @@ FaderPort8::~FaderPort8 ()
 
        if (_input_port) {
                DEBUG_TRACE (DEBUG::FaderPort8, string_compose ("unregistering input port %1\n", boost::shared_ptr<ARDOUR::Port>(_input_port)->name()));
+               _input_port->disconnect_all ();
+               _input_port->drain (5000, 50000);
+               _input_port->clear ();
                AudioEngine::instance()->unregister_port (_input_port);
                _input_port.reset ();
        }
@@ -461,7 +464,7 @@ FaderPort8::midi_input_handler (Glib::IOCondition ioc, boost::weak_ptr<ARDOUR::A
 {
        boost::shared_ptr<AsyncMIDIPort> port (wport.lock());
 
-       if (!port) {
+       if (!port || !_input_port) {
                return false;
        }