From 544424ee936201e4c5cb3d18fe26565c8c1e2e9d Mon Sep 17 00:00:00 2001 From: hikerstk Date: Sat, 8 Nov 2008 04:14:42 +0000 Subject: [PATCH] Fixed more bugs related to destroying the objects. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2425 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/karts/kart_model.cpp | 7 ++++--- src/karts/kart_properties_manager.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/karts/kart_model.cpp b/src/karts/kart_model.cpp index 482f14dbc..e3d089da8 100755 --- a/src/karts/kart_model.cpp +++ b/src/karts/kart_model.cpp @@ -65,10 +65,11 @@ void KartModel::loadInfo(const lisp::Lisp* lisp) */ KartModel::~KartModel() { + // This automatically frees the wheels and the kart model. + // m_root can be zero in case of STKConfig, which has a kart_properties + // attribute (for the default values) as well. + if(m_root) m_root->removeAllKids(); ssgDeRefDelete(m_root); - for(unsigned int i=0; i<4; i++) - if(m_wheel_model[i]) ssgDeRefDelete(m_wheel_model[i]); - } // ~KartModel // ---------------------------------------------------------------------------- diff --git a/src/karts/kart_properties_manager.cpp b/src/karts/kart_properties_manager.cpp index 1fbd4c701..b70b1d4a9 100644 --- a/src/karts/kart_properties_manager.cpp +++ b/src/karts/kart_properties_manager.cpp @@ -46,7 +46,12 @@ KartPropertiesManager::~KartPropertiesManager() { for(KartPropertiesVector::iterator i = m_karts_properties.begin(); i != m_karts_properties.end(); ++i) - delete *i; + { + delete *i; + // Set the entry in the kart properties vector to 0, otherwise + // memory errors happen. + m_karts_properties[i-m_karts_properties.begin()] = NULL; + } } // ~KartPropertiesManager //-----------------------------------------------------------------------------