From f0227bfd19fe23ac73d35724d9339b16e8e7219b Mon Sep 17 00:00:00 2001 From: auria Date: Mon, 15 Nov 2010 18:41:11 +0000 Subject: [PATCH] Don't crash when music not found git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6573 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/states_screens/grand_prix_lose.cpp | 11 ++++++++-- src/states_screens/grand_prix_win.cpp | 12 ++++++++--- src/tracks/track.cpp | 28 +++++++++++++++++--------- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/states_screens/grand_prix_lose.cpp b/src/states_screens/grand_prix_lose.cpp index d70062a6b..3da4c7b07 100644 --- a/src/states_screens/grand_prix_lose.cpp +++ b/src/states_screens/grand_prix_lose.cpp @@ -56,7 +56,15 @@ GrandPrixLose::GrandPrixLose() : Screen("grand_prix_lose.stkgui") m_throttle_FPS = false; - m_music = music_manager->getMusicInformation(file_manager->getMusicFile("lose_theme.music")); + try + { + m_music = music_manager->getMusicInformation(file_manager->getMusicFile("lose_theme.music")); + } + catch (std::exception& e) + { + fprintf(stderr, "%s", e.what()); + m_music = NULL; + } } // GrandPrixLose // ------------------------------------------------------------------------------------- @@ -74,7 +82,6 @@ void GrandPrixLose::loadedFromFile() void GrandPrixLose::init() { Screen::init(); - //music_manager->startMusic(music_manager->getMusicInformation(file_manager->getMusicFile("lose_theme.music"))); m_phase = 1; m_sky_angle = 0.0f; diff --git a/src/states_screens/grand_prix_win.cpp b/src/states_screens/grand_prix_win.cpp index d750ef336..e9bc3a101 100644 --- a/src/states_screens/grand_prix_win.cpp +++ b/src/states_screens/grand_prix_win.cpp @@ -37,7 +37,15 @@ GrandPrixWin::GrandPrixWin() : Screen("grand_prix_win.stkgui") m_throttle_FPS = false; - m_music = music_manager->getMusicInformation(file_manager->getMusicFile("win_theme.music")); + try + { + m_music = music_manager->getMusicInformation(file_manager->getMusicFile("win_theme.music")); + } + catch (std::exception& e) + { + fprintf(stderr, "%s", e.what()); + m_music = NULL; + } } // GrandPrixWin // ------------------------------------------------------------------------------------- @@ -130,8 +138,6 @@ void GrandPrixWin::init() unlocked_label->add(); } - - //music_manager->startMusic(music_manager->getMusicInformation(file_manager->getMusicFile("win_theme.music"))); m_phase = 1; m_sky_angle = 0.0f; diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 9aa9d897e..fdc08ee2e 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -263,18 +263,26 @@ void Track::getMusicInformation(std::vector& filenames, } if(!mi) { - std::string shared_name = file_manager->getMusicFile(filenames[i]); - if(shared_name!="") + try { - try + std::string shared_name = file_manager->getMusicFile(filenames[i]); + if(shared_name!="") { - mi = music_manager->getMusicInformation(shared_name); - } - catch(std::runtime_error) - { - mi = NULL; - } - } // shared_name!="" + try + { + mi = music_manager->getMusicInformation(shared_name); + } + catch(std::runtime_error) + { + mi = NULL; + } + } // shared_name!="" + } + catch (std::exception& e) + { + mi = NULL; + } + } if(!mi) {