Fix illegal iterator usage.
authorDavid Robillard <d@drobilla.net>
Mon, 1 Feb 2010 20:03:25 +0000 (20:03 +0000)
committerDavid Robillard <d@drobilla.net>
Mon, 1 Feb 2010 20:03:25 +0000 (20:03 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@6613 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/surfaces/generic_midi/generic_midi_control_protocol.cc

index db29a4c70aab1c9b41689c6abb5974a762e30e9a..08c0e7a1257621eb56587819e0719842f1694001 100644 (file)
@@ -388,12 +388,14 @@ GenericMidiControlProtocol::delete_binding (PBD::Controllable* control)
        if (control != 0) {
                Glib::Mutex::Lock lm2 (controllables_lock);
                
-               for (MIDIControllables::iterator iter = controllables.begin(); iter != controllables.end(); ++iter) {
+               for (MIDIControllables::iterator iter = controllables.begin(); iter != controllables.end();) {
                        MIDIControllable* existingBinding = (*iter);
                        
                        if (control == (existingBinding->get_controllable())) {
                                delete existingBinding;
-                               controllables.erase (iter);
+                               iter = controllables.erase (iter);
+                       } else {
+                               ++iter;
                        }
                        
                }
@@ -414,7 +416,7 @@ GenericMidiControlProtocol::create_binding (PBD::Controllable* control, int pos,
 
                // Remove any old binding for this midi channel/type/value pair
                // Note:  can't use delete_binding() here because we don't know the specific controllable we want to remove, only the midi information
-               for (MIDIControllables::iterator iter = controllables.begin(); iter != controllables.end(); ++iter) {
+               for (MIDIControllables::iterator iter = controllables.begin(); iter != controllables.end();) {
                        MIDIControllable* existingBinding = (*iter);
                        
                        if ((existingBinding->get_control_channel() & 0xf ) == channel &&
@@ -422,7 +424,9 @@ GenericMidiControlProtocol::create_binding (PBD::Controllable* control, int pos,
                            (existingBinding->get_control_type() & 0xf0 ) == MIDI::controller) {
                                
                                delete existingBinding;
-                               controllables.erase (iter);
+                               iter = controllables.erase (iter);
+                       } else {
+                               ++iter;
                        }
                        
                }