Perform decent error checking when getting music file, previous code would silently return an empty file. Fixed the use of the 'smart' function used too early when loading title music

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6252 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2010-10-11 19:19:31 +00:00
parent 6765a8a278
commit b957d7923a
3 changed files with 21 additions and 5 deletions

View File

@ -45,6 +45,8 @@ MusicInformation::MusicInformation(const std::string& filename) throw (std::runt
m_gain = 1.0f;
m_adjusted_gain = 1.0f;
assert(filename.size() > 0);
if (StringUtils::getExtension(filename) != "music")
{
// Create information just from ogg file
@ -111,6 +113,8 @@ MusicInformation::MusicInformation(const std::string& filename) throw (std::runt
m_fast_filename = path + "/" + m_fast_filename;
}
assert(m_normal_filename.size() > 0);
} // MusicInformation
//-----------------------------------------------------------------------------

View File

@ -231,8 +231,16 @@ void STKConfig::getAllData(const XMLNode * root)
{
std::string title_music;
music_node->get("title", &title_music);
m_title_music = new MusicInformation(
file_manager->getMusicFile(title_music) );
assert(title_music.size() > 0);
try
{
m_title_music = new MusicInformation(file_manager->getDataDir() + "/music/" + title_music);
}
catch (std::runtime_error& e)
{
fprintf(stderr, "Cannot load title music : %s\n", e.what());
}
}
if(const XMLNode *history_node = root->getNode("history"))

View File

@ -571,7 +571,11 @@ std::string FileManager::getLogFile(const std::string& fname) const
std::string FileManager::getMusicFile(const std::string& fname) const
{
std::string path;
findFile(path, fname, m_music_search_path);
const bool success = findFile(path, fname, m_music_search_path);
if (!success)
{
throw std::runtime_error("[FileManager::getMusicFile] Cannot find music file <" + fname + ">");
}
return path;
} // getMusicFile