Skip to content

Commit

Permalink
Issue #542: crashes when going to last sheet of animation in RAINBOW …
Browse files Browse the repository at this point in the history
…show
  • Loading branch information
rmpowell77 committed Nov 14, 2024
1 parent 985f83f commit 8a4766e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions LATEST_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Bugs addressed in this release:
* [#497](../../issues/497) Animate ctor should be explicit
* [#518](../../issues/518) Animation looks wrong
* [#540](../../issues/540) Current 3.7.1 does not run
* [#542](../../issues/542) crashes when going to last sheet of animation in RAINBOW show

Other changes:

Expand Down
2 changes: 1 addition & 1 deletion src/AnimationView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void AnimationView::RefreshFrame()
void AnimationView::RefreshAnimationSheet()
{
if (mAnimation) {
mCurrentBeat = mAnimation->GetTotalNumberBeatsUpTo(mView->GetCurrentSheetNum());
mCurrentBeat = mAnimation->GetTotalNumberBeatsUpTo(mAnimation->ShowSheetToAnimSheetTranslate(mView->GetCurrentSheetNum()));
RefreshFrame();
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/core/CalChartAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ auto AnimateShow(const Show& show) -> std::tuple<Sheets, std::vector<Errors>>
auto sheets = std::vector<Animate::Sheet>{};
auto endSheet = show.GetSheetEnd();

auto runningIndex = std::vector<unsigned>{};
for (auto curr_sheet = show.GetSheetBegin(); curr_sheet != endSheet; ++curr_sheet) {
runningIndex.push_back(curr_sheet->IsInAnimation() ? 1 : 0);
}
std::exclusive_scan(runningIndex.begin(), runningIndex.end(), runningIndex.begin(), 0);

for (auto curr_sheet = show.GetSheetBegin(); curr_sheet != endSheet; ++curr_sheet) {

if (!curr_sheet->IsInAnimation()) {
Expand Down Expand Up @@ -136,7 +142,7 @@ auto AnimateShow(const Show& show) -> std::tuple<Sheets, std::vector<Errors>>
sheets.emplace_back(curr_sheet->GetName(), numBeats, theCommands);
}

return { Animate::Sheets{ sheets }, animationErrors };
return { Animate::Sheets{ sheets, runningIndex }, animationErrors };
}
}

Expand Down
1 change: 1 addition & 0 deletions src/core/CalChartAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class Animation {

[[nodiscard]] auto GenPathToDraw(unsigned whichSheet, unsigned point, Coord::units endRadius) const { return mSheets.GeneratePathToDraw(whichSheet, point, endRadius); }

[[nodiscard]] auto ShowSheetToAnimSheetTranslate(unsigned showSheet) const { return mSheets.ShowSheetToAnimSheetTranslate(showSheet); }
/*!
* @brief Generates JSON that could represent of all the marchers in an Online Viewer '.viewer' file.
* @param pointsOverSheets All of the points in all of the sheets.
Expand Down
3 changes: 2 additions & 1 deletion src/core/CalChartAnimationSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@ namespace {
}
}

Sheets::Sheets(std::vector<Sheet> const& sheets)
Sheets::Sheets(std::vector<Sheet> const& sheets, std::vector<unsigned> const& showSheetToAnimationSheet)
: mSheets(sheets)
, mRunningBeatCount{ GetRunningBeats(sheets) }
, mShowSheetToAnimationSheet{ showSheetToAnimationSheet }
{
}

Expand Down
5 changes: 4 additions & 1 deletion src/core/CalChartAnimationSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Sheet {

class Sheets {
public:
explicit Sheets(std::vector<Sheet> const& sheets);
explicit Sheets(std::vector<Sheet> const& sheets, std::vector<unsigned> const& showSheetToAnimationSheet = {});
[[nodiscard]] auto TotalSheets() const -> size_t { return mSheets.size(); }
[[nodiscard]] auto TotalBeats() const -> beats_t;
[[nodiscard]] auto BeatToSheetOffsetAndBeat(beats_t beat) const -> std::tuple<size_t, beats_t>;
Expand Down Expand Up @@ -141,9 +141,12 @@ class Sheets {

[[nodiscard]] auto toOnlineViewerJSON() const -> std::vector<std::vector<std::vector<nlohmann::json>>>;

[[nodiscard]] auto ShowSheetToAnimSheetTranslate(unsigned sheet) const { return mShowSheetToAnimationSheet.at(sheet); }

private:
std::vector<Sheet> mSheets;
std::vector<beats_t> mRunningBeatCount;
std::vector<unsigned> mShowSheetToAnimationSheet;
};

}

0 comments on commit 8a4766e

Please sign in to comment.