change ReplayPlayer -allocation/deallocation in worls, world crashed in dtor, if replay-file was not found

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1249 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
ikework 2007-09-19 18:28:48 +00:00
parent bf7cda5179
commit 76dc339f38
2 changed files with 20 additions and 9 deletions

View File

@ -1,4 +1,4 @@
// $Id$
// $Id: $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2007 Damien Morel <divdams@free.fr>
@ -25,14 +25,16 @@
#include "replay_base.hpp"
#include "replay_base.hpp"
// class managing:
// - the loading of replay-file
// - the rendering of the replay (interpolation if needed)
class ReplayPlayer : public ReplayBase
{
public:
ReplayPlayer() : ReplayBase() {}
virtual ~ReplayPlayer() { destroy(); }
void destroy() { ReplayBase::destroy(); }
};

View File

@ -208,7 +208,12 @@ World::World(const RaceSetup& raceSetup_) : m_race_setup(raceSetup_)
#ifdef HAVE_GHOST_REPLAY
m_replay_recorder.initRecorder( m_race_setup.getNumKarts() );
if( !loadReplayHumanReadable( "test1" ) ) delete m_p_replay_player;
m_p_replay_player = new ReplayPlayer;
if( !loadReplayHumanReadable( "test1" ) )
{
delete m_p_replay_player;
m_p_replay_player = NULL;
}
#endif
}
@ -243,8 +248,12 @@ World::~World()
#ifdef HAVE_GHOST_REPLAY
m_replay_recorder.destroy();
m_p_replay_player->destroy();
delete m_p_replay_player;
if( m_p_replay_player )
{
m_p_replay_player->destroy();
delete m_p_replay_player;
m_p_replay_player = NULL;
}
#endif
}
@ -469,8 +478,8 @@ bool World::saveReplayHumanReadable( std::string const &filename ) const
//-----------------------------------------------------------------------------
bool World::loadReplayHumanReadable( std::string const &filename )
{
delete m_p_replay_player;
m_p_replay_player = new ReplayPlayer();
assert( m_p_replay_player );
m_p_replay_player->destroy();
std::string path = ReplayBase::REPLAY_FOLDER + DIR_SEPARATOR;
path += filename + ".";