From e6be564be8a5145f8c6156dda8c383dea0258c4a Mon Sep 17 00:00:00 2001 From: Thai Pangsakulyanont Date: Sun, 17 Jul 2011 13:03:21 +0700 Subject: [PATCH] [timing] make sure the segments are sorted --- src/TimingData.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/TimingData.cpp b/src/TimingData.cpp index da8100c483..fd3db33b47 100644 --- a/src/TimingData.cpp +++ b/src/TimingData.cpp @@ -32,11 +32,17 @@ void TimingData::GetActualBPM( float &fMinBPMOut, float &fMaxBPMOut, float highe } } +struct ts_less : binary_function { + bool operator() (const TimingSegment *x, const TimingSegment *y) const { + return (*x) < (*y); + } +}; + void TimingData::AddSegment(TimingSegmentType tst, TimingSegment * seg) { vector &segs = this->allTimingSegments[tst]; // Unsure if this uses the proper comparison. - segs.insert(upper_bound(segs.begin(), segs.end(), seg), seg); + segs.insert(upper_bound(segs.begin(), segs.end(), seg, ts_less()), seg); } int TimingData::GetSegmentIndexAtRow(TimingSegmentType tst, @@ -984,6 +990,11 @@ float TimingData::GetDisplayedBeat( float fBeat ) const const vector &scrolls = this->allTimingSegments[SEGMENT_SCROLL]; vector::const_iterator it = scrolls.begin(), end = scrolls.end(); float fOutBeat = 0; + for( it = it + 1; it != end; it++ ) + { + ASSERT((*(it-1))->GetBeat() <= (*it)->GetBeat()); + } + it = scrolls.begin(); for( ; it != end; it++ ) { if( it+1 == end || fBeat <= (*(it+1))->GetBeat() )