From 3b885c312674feef410243bafeef1598238ebb18 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 10 Apr 2007 11:46:12 +0000 Subject: [PATCH] fix potential crash-causing coding errors when removing regionviews from the selection git-svn-id: svn://localhost/ardour2/trunk@1693 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/region_selection.cc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gtk2_ardour/region_selection.cc b/gtk2_ardour/region_selection.cc index 7ac7763773..8074383141 100644 --- a/gtk2_ardour/region_selection.cc +++ b/gtk2_ardour/region_selection.cc @@ -114,31 +114,33 @@ RegionSelection::remove_it (RegionView *rv) bool RegionSelection::remove (RegionView* rv) { - RegionSelection::iterator i; + RegionSelection::iterator r; - if ((i = find (begin(), end(), rv)) != end()) { - - erase (i); + if ((r = find (begin(), end(), rv)) != end()) { // remove from layer sorted list _bylayer.remove (rv); - if (empty()) { + if (size() == 1) { + + /* this is the last one, so when we delete it + we will be empty. + */ _current_start = 0; _current_end = 0; } else { - boost::shared_ptr region ((*i)->region()); - + boost::shared_ptr region ((*r)->region()); + if (region->first_frame() == _current_start) { /* reset current start */ nframes_t ref = max_frames; - for (i = begin (); i != end(); ++i) { + for (RegionSelection::iterator i = begin (); i != end(); ++i) { if (region->first_frame() < ref) { ref = region->first_frame(); } @@ -154,7 +156,7 @@ RegionSelection::remove (RegionView* rv) nframes_t ref = 0; - for (i = begin (); i != end(); ++i) { + for (RegionSelection::iterator i = begin (); i != end(); ++i) { if (region->first_frame() > ref) { ref = region->first_frame(); } @@ -164,6 +166,8 @@ RegionSelection::remove (RegionView* rv) } } + erase (r); + return true; }