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
This commit is contained in:
hikerstk 2012-04-09 23:18:37 +00:00
parent f69dbd2447
commit 8d96260858
8 changed files with 12 additions and 9 deletions

View File

@ -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);

View File

@ -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

View File

@ -25,7 +25,7 @@
#include "LinearMath/btTransform.h"
CannonAnimation::CannonAnimation(AbstractKart *kart, AnimationBase *ab)
: AbstractKartAnimation(kart)
: AbstractKartAnimation(kart, "CannonAnimation")
{
} // CannonAnimation

View File

@ -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

View File

@ -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.

View File

@ -65,6 +65,5 @@ public:
virtual ~ExplosionAnimation();
virtual void update(float dt);
virtual const std::string getName() const { return "Explosion"; }
}; // ExplosionAnimation
#endif

View File

@ -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());

View File

@ -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