From 8d9626085877ab877044ce6defde366ced049fb4 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Mon, 9 Apr 2012 23:18:37 +0000 Subject: [PATCH] Fixed crash in debug output: getName() of a kart animation would be called from inside the constructor of the kart animation, at which time virtual functions are not available yet. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11102 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/karts/abstract_kart_animation.cpp | 4 +++- src/karts/abstract_kart_animation.hpp | 8 ++++++-- src/karts/cannon_animation.cpp | 2 +- src/karts/cannon_animation.hpp | 1 - src/karts/explosion_animation.cpp | 2 +- src/karts/explosion_animation.hpp | 1 - src/karts/rescue_animation.cpp | 2 +- src/karts/rescue_animation.hpp | 1 - 8 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/karts/abstract_kart_animation.cpp b/src/karts/abstract_kart_animation.cpp index 2ff34aa6c..27bcef0da 100644 --- a/src/karts/abstract_kart_animation.cpp +++ b/src/karts/abstract_kart_animation.cpp @@ -19,10 +19,12 @@ #include "karts/abstract_kart.hpp" #include "karts/abstract_kart_animation.hpp" -AbstractKartAnimation::AbstractKartAnimation(AbstractKart *kart) +AbstractKartAnimation::AbstractKartAnimation(AbstractKart *kart, + const std::string &name) { m_timer = 0; m_kart = kart; + m_name = name; // Register this animation with the kart (which will free it // later). kart->setKartAnimation(this); diff --git a/src/karts/abstract_kart_animation.hpp b/src/karts/abstract_kart_animation.hpp index 8bca9c7ee..5133cd148 100644 --- a/src/karts/abstract_kart_animation.hpp +++ b/src/karts/abstract_kart_animation.hpp @@ -37,6 +37,9 @@ class AbstractKart; */ class AbstractKartAnimation: public NoCopy { +private: + /** Name of this animation, used for debug prints only. */ + std::string m_name; protected: /** A pointer to the kart which is animated by this class. */ AbstractKart *m_kart; @@ -45,7 +48,8 @@ protected: float m_timer; public: - AbstractKartAnimation(AbstractKart *kart); + AbstractKartAnimation(AbstractKart *kart, + const std::string &name); virtual ~AbstractKartAnimation() {} virtual void update(float dt); // ------------------------------------------------------------------------ @@ -53,7 +57,7 @@ public: #ifdef DEBUG /** To easily allow printing the name of the animation being used atm. * Used in AstractKart in case of an incorrect sequence of calls. */ - virtual const std::string getName() const = 0; + virtual const std::string getName() const { return m_name; } #endif }; // AbstractKartAnimation diff --git a/src/karts/cannon_animation.cpp b/src/karts/cannon_animation.cpp index 357ca2c5d..e690e08f3 100644 --- a/src/karts/cannon_animation.cpp +++ b/src/karts/cannon_animation.cpp @@ -25,7 +25,7 @@ #include "LinearMath/btTransform.h" CannonAnimation::CannonAnimation(AbstractKart *kart, AnimationBase *ab) - : AbstractKartAnimation(kart) + : AbstractKartAnimation(kart, "CannonAnimation") { } // CannonAnimation diff --git a/src/karts/cannon_animation.hpp b/src/karts/cannon_animation.hpp index a413485a0..d33246c45 100644 --- a/src/karts/cannon_animation.hpp +++ b/src/karts/cannon_animation.hpp @@ -42,7 +42,6 @@ public: CannonAnimation(AbstractKart *kart, AnimationBase *ab); virtual ~CannonAnimation(); virtual void update(float dt); - virtual const std::string getName() const {return "Cannon";} }; // CannonAnimation #endif diff --git a/src/karts/explosion_animation.cpp b/src/karts/explosion_animation.cpp index ac27bdd35..1c43db67b 100644 --- a/src/karts/explosion_animation.cpp +++ b/src/karts/explosion_animation.cpp @@ -58,7 +58,7 @@ ExplosionAnimation *ExplosionAnimation::create(AbstractKart *kart) ExplosionAnimation::ExplosionAnimation(AbstractKart *kart, const Vec3 &explosion_position, bool direct_hit) - : AbstractKartAnimation(kart) + : AbstractKartAnimation(kart, "ExplosionAnimation") { m_xyz = m_kart->getXYZ(); // Ignore explosion that are too far away. diff --git a/src/karts/explosion_animation.hpp b/src/karts/explosion_animation.hpp index 4cc579f3c..a1602587d 100644 --- a/src/karts/explosion_animation.hpp +++ b/src/karts/explosion_animation.hpp @@ -65,6 +65,5 @@ public: virtual ~ExplosionAnimation(); virtual void update(float dt); - virtual const std::string getName() const { return "Explosion"; } }; // ExplosionAnimation #endif diff --git a/src/karts/rescue_animation.cpp b/src/karts/rescue_animation.cpp index 1a180673e..c2683fc89 100644 --- a/src/karts/rescue_animation.cpp +++ b/src/karts/rescue_animation.cpp @@ -33,7 +33,7 @@ * \param kart Pointer to the kart which is animated. */ RescueAnimation::RescueAnimation(AbstractKart *kart, bool is_auto_rescue) - : AbstractKartAnimation(kart) + : AbstractKartAnimation(kart, "RescueAnimation") { m_referee = new Referee(*m_kart); m_kart->getNode()->addChild(m_referee->getSceneNode()); diff --git a/src/karts/rescue_animation.hpp b/src/karts/rescue_animation.hpp index 9b859a357..854d7a094 100644 --- a/src/karts/rescue_animation.hpp +++ b/src/karts/rescue_animation.hpp @@ -56,6 +56,5 @@ public: RescueAnimation(AbstractKart *kart, bool is_auto_rescue=false); virtual ~RescueAnimation(); virtual void update(float dt); - virtual const std::string getName() const { return "Rescue"; } }; // RescueAnimation #endif