From b957d7923afdc31024574a3372855999a17652dd Mon Sep 17 00:00:00 2001 From: auria Date: Mon, 11 Oct 2010 19:19:31 +0000 Subject: [PATCH] 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 --- src/audio/music_information.cpp | 4 ++++ src/config/stk_config.cpp | 16 ++++++++++++---- src/io/file_manager.cpp | 6 +++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/audio/music_information.cpp b/src/audio/music_information.cpp index 611000b8c..d88102d53 100644 --- a/src/audio/music_information.cpp +++ b/src/audio/music_information.cpp @@ -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 diff --git a/src/config/stk_config.cpp b/src/config/stk_config.cpp index c7dff2ded..612c72296 100644 --- a/src/config/stk_config.cpp +++ b/src/config/stk_config.cpp @@ -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")) diff --git a/src/io/file_manager.cpp b/src/io/file_manager.cpp index e63777b01..7b04ed92e 100644 --- a/src/io/file_manager.cpp +++ b/src/io/file_manager.cpp @@ -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