From 6a57baf193a2d120f0c800f0539b3a900b5e6264 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 13 Jul 2022 22:12:30 +0200 Subject: [PATCH] Fix MIDI note cut 1. Editor::cut_copy() calls begin_reversible_command ("cut MIDI") 2. Editor::cut_copy_midi calls mrv->cut_copy_clear() 3. MidiRegionView::cut_copy_clear calls start_note_diff_command() 4. second call to begin_reversible_command() - debug builds assert() here, optimized builds continue 5. abort_reversible_command() is called, _current_trans = NULL; 6. MidiModel::apply_diff_command_as_subcommand() 7. Session::add_command, segfault because _current_trans == NULL ``` An UNDO transaction was started while a prior command was underway. Aborting command (midi edit) and prior (cut MIDI) ``` --- gtk2_ardour/midi_region_view.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 36b01a6325..8185da5c80 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -3764,21 +3764,28 @@ MidiRegionView::cut_copy_clear (Editing::CutCopyOp op) if (op != Copy) { - start_note_diff_command(); for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) { switch (op) { case Copy: break; case Delete: - case Cut: case Clear: + start_note_diff_command(); + /* fallthrough */ + case Cut: + /* for Cut, Editor::cut_copy already started an undo operation, + * so we cannot call start_note_diff_command () + */ + if (!_note_diff_command) { + _note_diff_command = _model->new_note_diff_command ("Cut"); + } note_diff_remove_note (*i); break; } } - apply_note_diff(); + apply_note_diff (op == Cut); } }