aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMax Horn2011-05-17 12:01:34 +0200
committerMax Horn2011-05-17 12:17:27 +0200
commit44b798d1072a32ee2142e8041fe3007e0b6b8e95 (patch)
tree686bbb0acd4b1438fdac1323cdbb61035aeecbf9 /engines
parentf04d6c6ee5872e5d82ddf7376778259b4428673a (diff)
downloadscummvm-rg350-44b798d1072a32ee2142e8041fe3007e0b6b8e95.tar.gz
scummvm-rg350-44b798d1072a32ee2142e8041fe3007e0b6b8e95.tar.bz2
scummvm-rg350-44b798d1072a32ee2142e8041fe3007e0b6b8e95.zip
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.
Diffstat (limited to 'engines')
-rw-r--r--engines/agi/agi.cpp16
-rw-r--r--engines/agi/agi.h1
-rw-r--r--engines/agi/preagi.cpp2
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");