Skip to content

Commit

Permalink
Issue: #581: Calchart 3.7.1 crashes on loading a show (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmpowell77 authored Jan 8, 2025
1 parent 7777c28 commit 094d1ea
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
2 changes: 2 additions & 0 deletions LATEST_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

Bugs addressed in this release:

* [#581](../../issues/581) Calchart 3.7.1 crashes on loading a show

Other changes:

5 changes: 2 additions & 3 deletions src/core/CalChartAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,15 @@ auto AnimateShow(const Show& show) -> Sheets
}
return std::nullopt;
}(nextAnimationSheet);
auto const& cont = curr_sheet->GetContinuityBySymbol(current_symbol).GetParsedContinuity();
auto empty_cont = std::vector<std::unique_ptr<Cont::Procedure>>{};
auto cont = curr_sheet->GetContinuityBySymbol(current_symbol);
return CalChart::Animate::CreateCompileResult(
AnimationData{
static_cast<unsigned>(whichMarcher),
curr_sheet->GetPoint(whichMarcher),
endPosition,
numBeats,
isLastSheet },
curr_sheet->ContinuityInUse(current_symbol) ? cont : empty_cont,
curr_sheet->ContinuityInUse(current_symbol) ? &cont : nullptr,
variablesStates);
}));

Expand Down
14 changes: 7 additions & 7 deletions src/core/CalChartAnimationCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ struct CompileState : public Compile {

auto CreateCompileResult(
AnimationData const& animationData,
Proceedures const& proceedures,
Continuity const* proceedures,
Variables& variablesStates) -> CompileResult
{
auto ac = CompileState(animationData, variablesStates);

// no continuity was specified
if (proceedures.empty()) {
if (proceedures == nullptr || !proceedures->HasParsedContinuity()) {
if (animationData.isLastAnimationSheet) {
// use MTRM E
Cont::ProcMTRM defcont(std::make_unique<Cont::ValueDefined>(Cont::CC_E));
Expand All @@ -78,11 +78,11 @@ auto CreateCompileResult(
Cont::ProcEven defcont(std::make_unique<Cont::ValueFloat>(ac.GetBeatsRemaining()), std::make_unique<Cont::NextPoint>());
defcont.Compile(ac);
}
}

// compile all the commands
for (auto const& proc : proceedures) {
proc->Compile(ac);
} else {
// compile all the commands
for (auto const& proc : proceedures->GetParsedContinuity()) {
proc->Compile(ac);
}
}

// report if the point didn't make it
Expand Down
2 changes: 1 addition & 1 deletion src/core/CalChartAnimationCompile.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct AnimationData {

auto CreateCompileResult(
AnimationData const& animationData,
Proceedures const& proceedures,
Continuity const* proceedures,
Variables& variablesStates) -> CompileResult;

struct Compile {
Expand Down
1 change: 1 addition & 0 deletions src/core/CalChartContinuity.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Continuity {
[[nodiscard]] auto Serialize() const -> std::vector<std::byte>;

std::vector<std::unique_ptr<Cont::Procedure>> const& GetParsedContinuity() const noexcept { return m_parsedContinuity; }
[[nodiscard]] auto HasParsedContinuity() const { return !m_parsedContinuity.empty(); }
auto GetText() const { return m_legacyText; }

friend void swap(Continuity& lhs, Continuity& rhs)
Expand Down
14 changes: 9 additions & 5 deletions tests/CalChartContinuityTokenTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ auto GetCompiledResults(Sheets const& sheets, Conts const& proc)
true
};

return Animate::CreateCompileResult(animationData, proc, vars);
return Animate::CreateCompileResult(animationData, &proc, vars);
}

auto CreateSheetsForTest(Coord begin, Coord end, int beats)
Expand Down Expand Up @@ -84,7 +84,8 @@ TEST_CASE("Fountain", "CalChartContinuityToken")
auto procs = std::vector<std::unique_ptr<Cont::Procedure>>{};
procs.push_back(std::move(uut));
auto sheets = CreateSheetsForTest({ 0, 0 }, { 8, 16 }, 14);
auto [compiledResults, errors] = GetCompiledResults(sheets, procs);
auto continuity = Continuity(std::move(procs));
auto [compiledResults, errors] = GetCompiledResults(sheets, continuity);

auto goldCompile = std::vector<Animate::Command>{
Animate::CommandMove{ Coord{ 0, 0 }, 6, Coord{ 128, 128 } },
Expand All @@ -105,7 +106,8 @@ TEST_CASE("Fountain with nulls", "CalChartContinuityToken")
auto procs = std::vector<std::unique_ptr<Cont::Procedure>>{};
procs.push_back(std::move(uut));
auto sheets = CreateSheetsForTest({ 0, 0 }, { 8, 16 }, 16);
auto [compiledResults, errors] = GetCompiledResults(sheets, procs);
auto continuity = Continuity(std::move(procs));
auto [compiledResults, errors] = GetCompiledResults(sheets, continuity);

auto goldCompile = std::vector<Animate::Command>{
Animate::CommandMove{ Coord{ 0, 0 }, 8, Coord{ 128, 128 } },
Expand All @@ -127,7 +129,8 @@ TEST_CASE("HSCM", "CalChartContinuityToken")
auto procs = std::vector<std::unique_ptr<Cont::Procedure>>{};
procs.push_back(std::move(uut));
auto sheets = CreateSheetsForTest({ 0, 0 }, { -8, 0 }, { 8, -2 }, { 0, 0 }, 40);
auto [compiledResults, errors] = GetCompiledResults(sheets, procs);
auto continuity = Continuity(std::move(procs));
auto [compiledResults, errors] = GetCompiledResults(sheets, continuity);

auto goldCompile = std::vector<Animate::Command>{
Animate::CommandMove{ Coord{ 0, 0 }, 9, Coord{ -16 * 9, 0 } },
Expand All @@ -151,7 +154,8 @@ TEST_CASE("DMCM", "CalChartContinuityToken")
auto procs = std::vector<std::unique_ptr<Cont::Procedure>>{};
procs.push_back(std::move(uut));
auto sheets = CreateSheetsForTest({ 0, 0 }, { -8, 8 }, { 8, -10 }, { 0, 0 }, 40);
auto [compiledResults, errors] = GetCompiledResults(sheets, procs);
auto continuity = Continuity(std::move(procs));
auto [compiledResults, errors] = GetCompiledResults(sheets, continuity);

auto goldCompile = std::vector<Animate::Command>{
Animate::CommandMove{ Coord{ 0, 0 }, 9, Coord{ -16 * 9, 16 * 9 } },
Expand Down

0 comments on commit 094d1ea

Please sign in to comment.