From 00b98173ca90eed4f9f3006ff7e32693e15032b0 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Tue, 3 Feb 2009 01:01:23 +0000 Subject: [PATCH] Fixed crashes caused by having an old user config file (which can contain invalid kart or track groups, or an invalid kart id). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@3099 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- ChangeLog | 4 ++++ src/gui/char_sel.cpp | 7 ++++++- src/gui/track_sel.cpp | 6 ++++++ src/karts/kart_properties_manager.cpp | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9342edf8f..dc3209f76 100755 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,10 @@ SuperTuxKart SVN - Fixed several bugs related to track and character group selection. - Plunger would stay in face after a restart of a race - Prevented incorrect rescues in Fort magma. + - Added slowdown for karts driving backwards + - Fixed crash if the user_config contained an invalid last used + kart id (e.g. too big because it's from a previous installation + with more karts), kart or track group. * Code cleanup: - Removed all snprintfs and constants defining a maximum message size. diff --git a/src/gui/char_sel.cpp b/src/gui/char_sel.cpp index 8c94dd828..393486e7b 100644 --- a/src/gui/char_sel.cpp +++ b/src/gui/char_sel.cpp @@ -247,8 +247,13 @@ void CharSel::updateScrollPosition() void CharSel::switchGroup() { m_index_avail_karts.clear(); - const std::vector &karts = + bool group_exist = + kart_properties_manager->getKartsInGroup(user_config->m_kart_group).size()>0; + if(!group_exist) user_config->m_kart_group = "standard"; + + const std::vector &karts = kart_properties_manager->getKartsInGroup(user_config->m_kart_group); + for(unsigned int i=0; ikartAvailable(karts[i])) diff --git a/src/gui/track_sel.cpp b/src/gui/track_sel.cpp index 00913e420..aa58a1dc6 100644 --- a/src/gui/track_sel.cpp +++ b/src/gui/track_sel.cpp @@ -166,6 +166,12 @@ void TrackSel::updateScrollPosition() void TrackSel::switchGroup() { m_index_avail_tracks.clear(); + bool group_available = + (RaceManager::isBattleMode( race_manager->getMinorMode() ) + ? track_manager->getArenasInGroup(user_config->m_track_group) + : track_manager->getTracksInGroup(user_config->m_track_group)).size()>0; + if(!group_available) + user_config->m_track_group = "standard"; const std::vector &tracks = RaceManager::isBattleMode( race_manager->getMinorMode() ) ? diff --git a/src/karts/kart_properties_manager.cpp b/src/karts/kart_properties_manager.cpp index 49659b394..80f44c8c8 100644 --- a/src/karts/kart_properties_manager.cpp +++ b/src/karts/kart_properties_manager.cpp @@ -223,6 +223,7 @@ bool KartPropertiesManager::testAndSetKart(int kartid) */ bool KartPropertiesManager::kartAvailable(int kartid) { + if(kartid<0 || kartid>=(int)m_kart_available.size()) return false; if(!m_kart_available[kartid]) return false; std::vector::iterator it; for (it = m_selected_karts.begin(); it < m_selected_karts.end(); it++)