Skip to content

Commit

Permalink
force reload songs if they don't have a valid music path when beginni…
Browse files Browse the repository at this point in the history
…ng gameplay
  • Loading branch information
TerraDOOM authored and MinaciousGrace committed Oct 6, 2018
1 parent bd0fff5 commit f43a7c2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/ScreenGameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,11 @@ ScreenGameplay::LoadNextSong()
int iPlaySongIndex = GAMESTATE->GetCourseSongIndex();
iPlaySongIndex %= m_apSongsQueue.size();
GAMESTATE->m_pCurSong.Set(m_apSongsQueue[iPlaySongIndex]);
// Check if the music actually exists, this is to avoid an issue in AutoKeysounds.cpp,
// where the reader will ignore whether the file opener function actually returned
// a valid object or an error. - Terra
GAMESTATE->m_pCurSong.Get()->ReloadIfNoMusic();

STATSMAN->m_CurStageStats.m_vpPlayedSongs.push_back(GAMESTATE->m_pCurSong);

// Force immediate fail behavior changed to theme metric by Kyz.
Expand Down
14 changes: 13 additions & 1 deletion src/Song.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "global.h"
#include "global.h"
#include "FontCharAliases.h"
#include "GameManager.h"
#include "RageLog.h"
Expand Down Expand Up @@ -492,6 +492,18 @@ Song::ReloadFromSongDir(const RString& sDir)
return true;
}

// Check if the music file actually exists, if not, reload from disk, and if that fails,
// just crash - Terra
void
Song::ReloadIfNoMusic() {
RString sMusicPath = GetMusicPath();
if (sMusicPath.empty() || !DoesFileExist(sMusicPath)) {
ASSERT_M(ReloadFromSongDir(),
"No music, so tried to reload from song dir but "
"ReloadFromSongDir failed");
}
}

bool
Song::HasAutosaveFile()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Song.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef SONG_H
#ifndef SONG_H
#define SONG_H

#include "Difficulty.h"
Expand Down Expand Up @@ -98,6 +98,7 @@ class Song
// This one takes the effort to reuse Steps pointers as best as it can
bool ReloadFromSongDir(const RString& sDir);
bool ReloadFromSongDir() { return ReloadFromSongDir(GetSongDir()); }
void ReloadIfNoMusic();

RString m_sFileHash;
RString GetFileHash();
Expand Down

0 comments on commit f43a7c2

Please sign in to comment.