From eeb25286127cb6acaa6cc6b74cb1c46722870355 Mon Sep 17 00:00:00 2001 From: Michael Votaw Date: Tue, 19 Dec 2023 16:20:51 -0600 Subject: [PATCH] If a song has any time signatures defined, but doesn't include for for beat 0, add one. (Fixes a crash that can occur with some songs if functions like TimingData::NoteRowToMeasureAndBeat are called for rows that don't have a time signature defined) --- src/NotesLoaderSM.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index b6af41deac..fa64b67e6c 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -772,6 +772,7 @@ void SMLoader::ProcessDelays( TimingData &out, const RString line, const int row void SMLoader::ProcessTimeSignatures( TimingData &out, const RString line, const int rowsPerBeat ) { std::vector vs1; + std::vector segments; split( line, ",", vs1 ); for (RString const &s1 : vs1) @@ -818,8 +819,21 @@ void SMLoader::ProcessTimeSignatures( TimingData &out, const RString line, const fBeat, iDenominator ); continue; } + segments.push_back( TimeSignatureSegment(BeatToNoteRow(fBeat), iNumerator, iDenominator) ); + } + + // If there are any time signatures defined, but there isn't one + // for the very first beat of the song, then add one. + // Without it, calls to functions like TimingData::NoteRowToMeasureAndBeat + // can fail for charts that are otherwise valid. + if ( segments.size() > 0 && segments[0].GetRow() > 0 ) + { + out.AddSegment( TimeSignatureSegment(0, 4, 4) ); + } - out.AddSegment( TimeSignatureSegment(BeatToNoteRow(fBeat), iNumerator, iDenominator) ); + for( TimeSignatureSegment segment: segments ) + { + out.AddSegment( segment ); } }