When sorting course songs by GRADEBEST or GRADEWORST, check if GAMESTATE has a master player before calling SongUtil::SortSongPointerArrayByGrades().

This commit is contained in:
Michael Votaw
2023-12-13 09:12:21 -08:00
committed by teejusb
parent c9750159fb
commit 29a265713f
+5 -2
View File
@@ -383,11 +383,14 @@ static void CourseSortSongs( SongSort sort, std::vector<Song*> &vpPossibleSongs,
SongUtil::SortSongPointerArrayByNumPlays( vpPossibleSongs, PROFILEMAN->GetMachineProfile(), false ); // ascending SongUtil::SortSongPointerArrayByNumPlays( vpPossibleSongs, PROFILEMAN->GetMachineProfile(), false ); // ascending
break; break;
case SongSort_TopGrades: 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 SongUtil::SortSongPointerArrayByGrades( vpPossibleSongs, true ); // descending
break; break;
case SongSort_LowestGrades: case SongSort_LowestGrades:
if( PROFILEMAN ) if( PROFILEMAN && GAMESTATE->GetMasterPlayerNumber() != PlayerNumber_Invalid )
SongUtil::SortSongPointerArrayByGrades( vpPossibleSongs, false ); // ascending SongUtil::SortSongPointerArrayByGrades( vpPossibleSongs, false ); // ascending
break; break;
} }