Fix region boundary cache lookup segfault

When the cursor position is after the last item in the vector,
upper_bound returns the last given iterator, here:
`region_boundary_cache.end()`, which is invalid to dereference.

Furthermore prevent possible  duplicate prev/next pair at zero,
when using the video-timelime.
This commit is contained in:
Robin Gareus 2020-04-22 22:37:43 +02:00
parent ea16fc51d3
commit 485ac45477
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 8 additions and 2 deletions

View File

@ -2995,6 +2995,9 @@ Editor::snap_to_internal (MusicSample& start, RoundMode direction, SnapPref pref
prev = next;
prev--;
}
if (next == region_boundary_cache.end ()) {
next--;
}
if ((direction == RoundUpMaybe || direction == RoundUpAlways)) {
test = *next;

View File

@ -768,9 +768,12 @@ Editor::build_region_boundary_cache ()
}
}
//allow regions to snap to the video start (if any) as if it were a "region"
/* allow regions to snap to the video start (if any) as if it were a "region" */
if (ARDOUR_UI::instance()->video_timeline) {
region_boundary_cache.push_back (ARDOUR_UI::instance()->video_timeline->get_video_start_offset());
ARDOUR::samplepos_t vo = ARDOUR_UI::instance()->video_timeline->get_video_start_offset();
if (std::find (region_boundary_cache.begin(), region_boundary_cache.end(), vo) == region_boundary_cache.end()) {
region_boundary_cache.push_back (ARDOUR_UI::instance()->video_timeline->get_video_start_offset());
}
}
std::pair<samplepos_t, samplepos_t> ext = session_gui_extents (false);