prevent crash when loading midi port info about ports that no longer exist
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 18 Apr 2017 13:14:17 +0000 (14:14 +0100)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 18 Apr 2017 13:22:51 +0000 (14:22 +0100)
libs/ardour/port_manager.cc

index aa56ab8d438597a2b90baff1e5cce591a1ed48f9..268d7cb9feb3b6be80fe6d27089ffadb3b2f082b 100644 (file)
@@ -1207,19 +1207,25 @@ PortManager::fill_midi_port_info_locked ()
        for (MidiPortInfo::iterator x = midi_port_info.begin(); x != midi_port_info.end(); ++x) {
                PortEngine::PortHandle ph = _backend->get_port_by_name (x->first);
 
+               if (!ph) {
+                       /* port info saved from some condition where this port
+                        * existed, but no longer does (i.e. device unplugged
+                        * at present)
+                        */
+                       continue;
+               }
+
                if (x->second.pretty_name != x->first) {
                        /* name set in port info ... propagate */
                        _backend->set_port_property (ph, "http://jackaudio.org/metadata/pretty-name", x->second.pretty_name, string());
                } else {
                        /* check with backend for pre-existing pretty name */
-                       if (ph) {
-                               string value;
-                               string type;
-                               if (0 == _backend->get_port_property (ph,
-                                                                     "http://jackaudio.org/metadata/pretty-name",
-                                                                     value, type)) {
-                                       x->second.pretty_name = value;
-                               }
+                       string value;
+                       string type;
+                       if (0 == _backend->get_port_property (ph,
+                                                             "http://jackaudio.org/metadata/pretty-name",
+                                                             value, type)) {
+                               x->second.pretty_name = value;
                        }
                }
        }