TEENAGENT: Migrate deinit functions to constructor/destructors.

This removes a number of memory leaks.
This commit is contained in:
D G Turner 2012-07-26 09:18:57 +01:00
parent 72adca69f3
commit f137c75e46
4 changed files with 19 additions and 22 deletions

View File

@ -27,7 +27,10 @@
namespace TeenAgent {
void Resources::deinit() {
Resources::Resources() {
}
Resources::~Resources() {
off.close();
on.close();
ons.close();

View File

@ -658,7 +658,8 @@ const uint16 dsAddr_finalCredits7 = 0xe488; // "programming..."
class Resources {
public:
void deinit();
Resources();
~Resources();
bool loadArchives(const ADGameDescription *gd);
void loadOff(Graphics::Surface &surface, byte *palette, int id);

View File

@ -73,10 +73,20 @@ TeenAgentEngine::TeenAgentEngine(OSystem *system, const ADGameDescription *gd)
}
TeenAgentEngine::~TeenAgentEngine() {
delete music;
delete dialog;
res->deinit();
dialog = 0;
delete scene;
scene = 0;
delete inventory;
inventory = 0;
delete music;
music = 0;
_mixer->stopAll();
use_hotspots.clear();
delete res;
res = 0;
CursorMan.popCursor();
delete console;
DebugMan.clearAllDebugChannels();
@ -206,19 +216,6 @@ void TeenAgentEngine::init() {
}
}
void TeenAgentEngine::deinit() {
_mixer->stopAll();
delete scene;
scene = NULL;
delete inventory;
inventory = NULL;
//delete music;
//music = NULL;
use_hotspots.clear();
res->deinit();
CursorMan.popCursor();
}
Common::Error TeenAgentEngine::loadGameState(int slot) {
debug(0, "loading from slot %d", slot);
Common::ScopedPtr<Common::InSaveFile> in(_saveFileMan->openForLoading(Common::String::format("teenagent.%02d", slot)));
@ -579,10 +576,8 @@ Common::Error TeenAgentEngine::run() {
Object *current_object = scene->findObject(mouse);
while (_event->pollEvent(event)) {
if (event.type == Common::EVENT_RTL) {
deinit();
if (event.type == Common::EVENT_RTL)
return Common::kNoError;
}
if ((!scene_busy && inventory->processEvent(event)) || scene->processEvent(event))
continue;
@ -702,7 +697,6 @@ Common::Error TeenAgentEngine::run() {
}
} while (!shouldQuit());
deinit();
return Common::kNoError;
}

View File

@ -82,7 +82,6 @@ public:
virtual bool hasFeature(EngineFeature f) const;
void init();
void deinit();
void examine(const Common::Point &point, Object *object);
void use(Object *object);