Skip to content

Commit

Permalink
remove assert crash when getting most recent highscore
Browse files Browse the repository at this point in the history
it isnt totally necessary, we could just handle it better
  • Loading branch information
poco0317 committed Aug 29, 2020
1 parent 8ceedce commit 376d140
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/Etterna/Models/Misc/StageStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,11 @@ StageStats::FinalizeScores(bool /*bSummary*/)
// happens -mina
mostrecentscorekey = PlayerAI::pScoreData->GetScoreKey();
SCOREMAN->PutScoreAtTheTop(mostrecentscorekey);
SCOREMAN->GetMostRecentScore()->SetRadarValues(
hs.GetRadarValues());
if (SCOREMAN->GetMostRecentScore() == nullptr)
Locator::getLogger()->warn("MOST RECENT SCORE WAS EMPTY.");
else
SCOREMAN->GetMostRecentScore()->SetRadarValues(
hs.GetRadarValues());
}
}
zzz->m_lastSong.FromSong(GAMESTATE->m_pCurSong);
Expand Down
5 changes: 5 additions & 0 deletions src/Etterna/Screen/Others/ScreenEvaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ class LunaScreenEvaluation : public Luna<ScreenEvaluation>
{
CHECKPOINT_M("Checking for invalid modifiers on Highscore via Lua");
HighScore* hs = SCOREMAN->GetMostRecentScore();
if (hs == nullptr) {
Locator::getLogger()->warn("MOST RECENT SCORE WAS EMPTY.");
lua_pushboolean(L, true);
return 1;
}
CHECKPOINT_M("Getting Player Options from HighScore...");
PlayerOptions potmp;
potmp.FromString(hs->GetModifiers());
Expand Down
2 changes: 1 addition & 1 deletion src/Etterna/Screen/Others/ScreenSelectMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,7 @@ class LunaScreenSelectMusic : public Luna<ScreenSelectMusic>
SCOREMAN->camefromreplay =
false; // disallow viewing online score eval screens -mina
auto* score = SCOREMAN->GetMostRecentScore();
if (!score->LoadReplayData()) {
if (score == nullptr || !score->LoadReplayData()) {
SCREENMAN->SystemMessage(
"Failed to load Replay Data for some reason.");
lua_pushboolean(L, false);
Expand Down
5 changes: 4 additions & 1 deletion src/Etterna/Singletons/ScoreManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,10 @@ class LunaScoreManager : public Luna<ScoreManager>
{
// this _should_ always be viable if only called from eval
auto* last = p->GetMostRecentScore();
last->PushSelf(L);
if (last == nullptr)
lua_pushnil(L);
else
last->PushSelf(L);
return 1;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Etterna/Singletons/ScoreManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ class ScoreManager
"Temp score for Replay & Practice viewing was empty.");
return tempscoreforonlinereplayviewing;
}
ASSERT_M(!AllScores.empty(), "Profile has no Scores.");
// Allow Lua to receive null HS here
if (AllScores.empty())
return nullptr;
return AllScores.back();
}
void PutScoreAtTheTop(const std::string& scorekey)
Expand Down

0 comments on commit 376d140

Please sign in to comment.