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:
parent
6765a8a278
commit
b957d7923a
@ -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
|
||||
@ -110,6 +112,8 @@ MusicInformation::MusicInformation(const std::string& filename) throw (std::runt
|
||||
{
|
||||
m_fast_filename = path + "/" + m_fast_filename;
|
||||
}
|
||||
|
||||
assert(m_normal_filename.size() > 0);
|
||||
|
||||
} // MusicInformation
|
||||
|
||||
|
@ -222,17 +222,25 @@ void STKConfig::getAllData(const XMLNode * root)
|
||||
leader_node->get("time-per-kart", &m_leader_time_per_kart);
|
||||
}
|
||||
|
||||
if(const XMLNode *startup_node= root->getNode("startup"))
|
||||
if (const XMLNode *startup_node= root->getNode("startup"))
|
||||
{
|
||||
startup_node->get("penalty", &m_penalty_time );
|
||||
}
|
||||
|
||||
if(const XMLNode *music_node = root->getNode("music"))
|
||||
if (const XMLNode *music_node = root->getNode("music"))
|
||||
{
|
||||
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"))
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user