From 44b798d1072a32ee2142e8041fe3007e0b6b8e95 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 17 May 2011 12:01:34 +0200 Subject: AGI: Unify RandomSource instantiation This fixes a leak in PreAGI games (which never deleted their RandomSource), ensures that PreAGI's RandomSource has a name (and hence is registered with the event recorder) and even slightly simplifies the AgiEngine destructor. --- engines/agi/agi.cpp | 16 ++++++++++------ engines/agi/agi.h | 1 + engines/agi/preagi.cpp | 2 -- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp index 101c149f0a..78316588b0 100644 --- a/engines/agi/agi.cpp +++ b/engines/agi/agi.cpp @@ -484,10 +484,16 @@ static const GameSettings agiSettings[] = { AgiBase::AgiBase(OSystem *syst, const AGIGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) { _noSaveLoadAllowed = false; + _rnd = new Common::RandomSource("agi"); + initFeatures(); initVersion(); } +AgiBase::~AgiBase() { + delete _rnd; +} + AgiEngine::AgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) : AgiBase(syst, gameDesc) { // Setup mixer @@ -495,8 +501,6 @@ AgiEngine::AgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) : AgiBas parseFeatures(); - _rnd = new Common::RandomSource("agi"); - DebugMan.addDebugChannel(kDebugLevelMain, "Main", "Generic debug level"); DebugMan.addDebugChannel(kDebugLevelResources, "Resources", "Resources debugging"); DebugMan.addDebugChannel(kDebugLevelSprites, "Sprites", "Sprites debugging"); @@ -647,10 +651,11 @@ void AgiEngine::initialize() { } AgiEngine::~AgiEngine() { - // If the engine hasn't been initialized yet via AgiEngine::initialize(), don't attempt to free any resources, - // as they haven't been allocated. Fixes bug #1742432 - AGI: Engine crashes if no game is detected + // If the engine hasn't been initialized yet via + // AgiEngine::initialize(), don't attempt to free any resources, as + // they haven't been allocated. Fixes bug #1742432 - AGI: Engine + // crashes if no game is detected if (_game.state == STATE_INIT) { - delete _rnd; // delete _rnd, as it is allocated in the constructor, not in initialize() return; } @@ -664,7 +669,6 @@ AgiEngine::~AgiEngine() { free(_game.sbufOrig); _gfx->deinitMachine(); delete _gfx; - delete _rnd; delete _console; free(_predictiveDictLine); diff --git a/engines/agi/agi.h b/engines/agi/agi.h index 0b941e4ecb..19343873ec 100644 --- a/engines/agi/agi.h +++ b/engines/agi/agi.h @@ -755,6 +755,7 @@ public: virtual void clearKeyQueue() = 0; AgiBase(OSystem *syst, const AGIGameDescription *gameDesc); + ~AgiBase(); virtual void clearImageStack() = 0; virtual void recordImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3, diff --git a/engines/agi/preagi.cpp b/engines/agi/preagi.cpp index 8eb2e7d6e3..c1a6cd33fe 100644 --- a/engines/agi/preagi.cpp +++ b/engines/agi/preagi.cpp @@ -42,8 +42,6 @@ PreAgiEngine::PreAgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) : // Setup mixer syncSoundSettings(); - _rnd = new Common::RandomSource(); - DebugMan.addDebugChannel(kDebugLevelMain, "Main", "Generic debug level"); DebugMan.addDebugChannel(kDebugLevelResources, "Resources", "Resources debugging"); DebugMan.addDebugChannel(kDebugLevelSprites, "Sprites", "Sprites debugging"); -- cgit v1.2.3