From 39c324b62015a76dbb2ae40f2ff8a6aed17f2b2f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 10 Dec 2022 22:59:58 -0700 Subject: [PATCH] temporal: fix ::get_grid() crash condition We cannot call TempoMetric::superclock_at (BBT_Time) if the BBT time is beyond the range of the current TempoMetric. We must discover that *before* we make that call, not as part of the test to see if we've exceeded the range. --- libs/temporal/tempo.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index 1e00a269cf..3d709503d6 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -2090,13 +2090,24 @@ TempoMap::get_grid (TempoMapPoints& ret, superclock_t start, superclock_t end, u } } - start = metric.superclock_at (bbt); + DEBUG_TRACE (DEBUG::Grid, string_compose ("pre-check overrun of next point with bbt @ %1 audio %2 point %3\n", bbt, start, *p)); - DEBUG_TRACE (DEBUG::Grid, string_compose ("check overrun of next point with bbt @ %1 audio %2 point %3\n", bbt, start, *p)); + bool reset = false; - if ((!next_point_is_bbt_marker && bbt >= p->bbt()) || (start >= p->sclock())) { + if (!next_point_is_bbt_marker && bbt >= p->bbt()) { + DEBUG_TRACE (DEBUG::Grid, string_compose ("we've reached/passed the next point via BBT, BBT %1 audio %2 point %3\n", bbt, start, *p)); + reset = true; + } else { + start = metric.superclock_at (bbt); + if (start >= p->sclock()) { + DEBUG_TRACE (DEBUG::Grid, string_compose ("we've reached/passed the next point via sclock, BBT %1 audio %2 point %3\n", bbt, start, *p)); + reset = true; + } + } - DEBUG_TRACE (DEBUG::Grid, string_compose ("we've reached/passed the next point, BBT %1 audio %2 point %3\n", bbt, start, *p)); + DEBUG_TRACE (DEBUG::Grid, string_compose ("check overrun of next point, reset required ? %4 with bbt @ %1 audio %2 point %3\n", bbt, start, *p, (reset ? "YES" : "NO"))); + + if (reset) { /* reset our sense of "now" to be wherever the point is */