Fix occasional crash when saving MIDI.
authorDavid Robillard <d@drobilla.net>
Tue, 30 Dec 2014 03:01:41 +0000 (22:01 -0500)
committerDavid Robillard <d@drobilla.net>
Tue, 30 Dec 2014 03:01:41 +0000 (22:01 -0500)
I can't figure out why a change has a NULL note; that shouldn't happen, but it
does.  Worse case scenario is some undo loss, so better to print something
informative and soldier on than crash.  Hopefully this will help track down the
real cause with more testing.

libs/ardour/midi_model.cc

index c9c71e7db931dafe5b5f5a6f9cf61b0ce9d0ee22..7f8a38454aa661a10ed46ab5fe91276bb10b1cbe 100644 (file)
@@ -582,8 +582,16 @@ MidiModel::NoteDiffCommand::marshal_change (const NoteChange& change)
        }
 
        ostringstream id_str;
-       id_str << change.note->id();
-       xml_change->add_property ("id", id_str.str());
+       if (change.note) {
+               id_str << change.note->id();
+               xml_change->add_property ("id", id_str.str());
+       } else if (change.note_id) {
+               warning << _("Change has no note, using note ID") << endmsg;
+               id_str << change.note_id;
+               xml_change->add_property ("id", id_str.str());
+       } else {
+               error << _("Change has no note or note ID") << endmsg;
+       }
 
        return *xml_change;
 }
@@ -593,6 +601,7 @@ MidiModel::NoteDiffCommand::unmarshal_change (XMLNode *xml_change)
 {
        XMLProperty* prop;
        NoteChange change;
+       change.note_id = 0;
 
        if ((prop = xml_change->property("property")) != 0) {
                change.property = (Property) string_2_enum (prop->value(), change.property);