From ec34c2137d3ba8fb4d8267b67955f87816d4094c Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 7 Oct 2023 11:01:23 -0600 Subject: [PATCH] avoid a crash when dragging a meter change near a BBT marker --- libs/temporal/tempo.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index 1699f91559..74b0158114 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -1970,8 +1970,16 @@ TempoMap::move_meter (MeterPoint const & mp, timepos_t const & when, bool earlie } else { bbt = bbt.round_down_to_bar (); } + /* Now find the correct TempoMetric for the new BBT position (which may + * differ from the one we determined earlier. + * + * The search for the correct meter will be limited by the meter we're + * dragging. But the search for the correct tempo needs to bounded by + * both the BBT *and* the beat position, in case there is an upcoming + * BBT marker. + */ - for (t = _tempos.begin(), prev_t = _tempos.end(); t != _tempos.end() && t->bbt() < bbt; ++t) { prev_t = t; } + for (t = _tempos.begin(), prev_t = _tempos.end(); t != _tempos.end() && t->bbt() < bbt && t->beats() < beats; ++t) { prev_t = t; } for (m = _meters.begin(), prev_m = _meters.end(); m != _meters.end() && m->bbt() < bbt && *m != mp; ++m) { prev_m = m; } if (prev_m == _meters.end()) {