From 29a265713fdb10e09d8c9dd4e971d18a568dd740 Mon Sep 17 00:00:00 2001 From: Michael Votaw Date: Fri, 1 Dec 2023 17:29:15 -0600 Subject: [PATCH] When sorting course songs by GRADEBEST or GRADEWORST, check if GAMESTATE has a master player before calling SongUtil::SortSongPointerArrayByGrades(). --- src/Course.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Course.cpp b/src/Course.cpp index 2cd668f5a8..5a2fe64921 100644 --- a/src/Course.cpp +++ b/src/Course.cpp @@ -383,11 +383,14 @@ static void CourseSortSongs( SongSort sort, std::vector &vpPossibleSongs, SongUtil::SortSongPointerArrayByNumPlays( vpPossibleSongs, PROFILEMAN->GetMachineProfile(), false ); // ascending break; case SongSort_TopGrades: - if( PROFILEMAN ) + // SongUtil::SortSongPointerArrayByGrades() will crash if called in a state where there's no current master player + // (for instance when returning to the Title Menu). + // A workaround is to just not call it if we know that GAMESTATE->GetMasterPlayerNumber() == PlayerNumber_Invalid + if( PROFILEMAN && GAMESTATE->GetMasterPlayerNumber() != PlayerNumber_Invalid ) SongUtil::SortSongPointerArrayByGrades( vpPossibleSongs, true ); // descending break; case SongSort_LowestGrades: - if( PROFILEMAN ) + if( PROFILEMAN && GAMESTATE->GetMasterPlayerNumber() != PlayerNumber_Invalid ) SongUtil::SortSongPointerArrayByGrades( vpPossibleSongs, false ); // ascending break; }