[Scummvm-cvs-logs] SF.net SVN: scummvm:[54185] scummvm/trunk/engines/toon

tdhs at users.sourceforge.net tdhs at users.sourceforge.net
Wed Nov 10 07:22:18 CET 2010


Revision: 54185
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54185&view=rev
Author:   tdhs
Date:     2010-11-10 06:22:18 +0000 (Wed, 10 Nov 2010)

Log Message:
-----------
TOON: Even more corrections to close memory leaks.

These corrections close a number of leaks in the Toon engine reported by running Valgrind with --leak-check=full option, but a few still remain.

Modified Paths:
--------------
    scummvm/trunk/engines/toon/anim.cpp
    scummvm/trunk/engines/toon/audio.cpp
    scummvm/trunk/engines/toon/character.cpp
    scummvm/trunk/engines/toon/drew.cpp
    scummvm/trunk/engines/toon/drew.h
    scummvm/trunk/engines/toon/flux.cpp
    scummvm/trunk/engines/toon/flux.h
    scummvm/trunk/engines/toon/hotspot.cpp
    scummvm/trunk/engines/toon/movie.cpp
    scummvm/trunk/engines/toon/resource.cpp
    scummvm/trunk/engines/toon/resource.h
    scummvm/trunk/engines/toon/script.cpp
    scummvm/trunk/engines/toon/script_func.cpp
    scummvm/trunk/engines/toon/text.cpp
    scummvm/trunk/engines/toon/toon.cpp

Modified: scummvm/trunk/engines/toon/anim.cpp
===================================================================
--- scummvm/trunk/engines/toon/anim.cpp	2010-11-10 04:30:24 UTC (rev 54184)
+++ scummvm/trunk/engines/toon/anim.cpp	2010-11-10 06:22:18 UTC (rev 54185)
@@ -108,6 +108,7 @@
 		}
 	}
 
+	//delete[] fileData;
 	delete[] finalBuffer;
 	return true;
 }

Modified: scummvm/trunk/engines/toon/audio.cpp
===================================================================
--- scummvm/trunk/engines/toon/audio.cpp	2010-11-10 04:30:24 UTC (rev 54184)
+++ scummvm/trunk/engines/toon/audio.cpp	2010-11-10 06:22:18 UTC (rev 54185)
@@ -44,10 +44,10 @@
 
 AudioManager::AudioManager(ToonEngine *vm, Audio::Mixer *mixer) : _vm(vm), _mixer(mixer) {
 	for (int32 i = 0; i < 16; i++)
-		_channels[i] = 0;
+		_channels[i] = NULL;
 
 	for (int32 i = 0; i < 4; i++) 
-		_audioPacks[i] = 0;
+		_audioPacks[i] = NULL;
 
 	for (int32 i = 0; i < 4; i++) {
 		_ambientSFXs[i]._delay = 0;
@@ -90,7 +90,7 @@
 
 	for (int32 i = 0; i < 16; i++) {
 		if (inst == _channels[i])
-			_channels[i] = 0;
+			_channels[i] = NULL;
 	}
 }
 
@@ -130,9 +130,7 @@
 		_currentMusicChannel = 0;
 	}
 
-	
-	//if (!_channels[_currentMusicChannel])
-	//	delete _channels[_currentMusicChannel];
+	delete _channels[_currentMusicChannel];
 	_channels[_currentMusicChannel] = new AudioStreamInstance(this, _mixer, srs, true);
 	_channels[_currentMusicChannel]->setVolume(_musicMuted ? 0 : 255);
 	_channels[_currentMusicChannel]->play(true, Audio::Mixer::kMusicSoundType);
@@ -159,6 +157,7 @@
 	else
 		stream = _audioPacks[1]->getStream(id);
 
+	delete _channels[2];
 	_channels[2] = new AudioStreamInstance(this, _mixer, stream);
 	_channels[2]->play(false, Audio::Mixer::kSpeechSoundType);
 	_channels[2]->setVolume(_voiceMuted ? 0 : 255);
@@ -240,10 +239,10 @@
 
 AudioStreamInstance::AudioStreamInstance(AudioManager *man, Audio::Mixer *mixer, Common::SeekableReadStream *stream , bool looping) {
 	_compBufferSize = 0;
-	_buffer = 0;
+	_buffer = NULL;
 	_bufferMaxSize = 0;
 	_mixer = mixer;
-	_compBuffer = 0;
+	_compBuffer = NULL;
 	_bufferOffset = 0;
 	_lastADPCMval1 = 0;
 	_lastADPCMval2 = 0;
@@ -269,6 +268,9 @@
 }
 
 AudioStreamInstance::~AudioStreamInstance() {
+	delete[] _buffer;
+	delete[] _compBuffer;
+
 	if (_man)
 		_man->removeInstance(this);
 }
@@ -319,15 +321,13 @@
 	_file->readSint32LE();
 
 	if (numCompressedBytes > _compBufferSize) {
-		if (_compBuffer)
-			delete[] _compBuffer;
+		delete[] _compBuffer;
 		_compBufferSize = numCompressedBytes;
 		_compBuffer = new uint8[_compBufferSize];
 	}
 
 	if (numDecompressedBytes > _bufferMaxSize) {
-		if (_buffer)
-			delete [] _buffer;
+		delete [] _buffer;
 		_bufferMaxSize = numDecompressedBytes;
 		_buffer = new int16[numDecompressedBytes];
 	}
@@ -450,9 +450,7 @@
 			_musicAttenuation = 1000;
 	}
 
-
 	_mixer->setChannelVolume(_handle, finalVolume * _musicAttenuation / 1000);
-
 }
 
 void AudioStreamInstance::stop(bool fade /*= false*/) {

Modified: scummvm/trunk/engines/toon/character.cpp
===================================================================
--- scummvm/trunk/engines/toon/character.cpp	2010-11-10 04:30:24 UTC (rev 54184)
+++ scummvm/trunk/engines/toon/character.cpp	2010-11-10 06:22:18 UTC (rev 54185)
@@ -31,7 +31,7 @@
 namespace Toon {
 
 Character::Character(ToonEngine *vm) : _vm(vm) {
-	_animationInstance = 0;
+	_animationInstance = NULL;
 	_shadowAnimationInstance = NULL;
 	_x = 0;
 	_y = 0;
@@ -66,6 +66,7 @@
 }
 
 Character::~Character(void) {
+	delete _animationInstance;
 	delete _shadowAnimationInstance;
 
 	delete _walkAnim;

Modified: scummvm/trunk/engines/toon/drew.cpp
===================================================================
--- scummvm/trunk/engines/toon/drew.cpp	2010-11-10 04:30:24 UTC (rev 54184)
+++ scummvm/trunk/engines/toon/drew.cpp	2010-11-10 06:22:18 UTC (rev 54185)
@@ -35,7 +35,7 @@
 	vm->getAnimationManager()->addInstance(_animationInstance);
 }
 
-CharacterDrew::~CharacterDrew(void) {
+CharacterDrew::~CharacterDrew() {
 }
 
 bool CharacterDrew::setupPalette() {

Modified: scummvm/trunk/engines/toon/drew.h
===================================================================
--- scummvm/trunk/engines/toon/drew.h	2010-11-10 04:30:24 UTC (rev 54184)
+++ scummvm/trunk/engines/toon/drew.h	2010-11-10 06:22:18 UTC (rev 54185)
@@ -36,7 +36,7 @@
 class CharacterDrew : public Character {
 public:
 	CharacterDrew(ToonEngine *vm);
-	virtual ~CharacterDrew(void);
+	virtual ~CharacterDrew();
 	bool setupPalette();
 	void setFacing(int32 facing);
 	void playStandingAnim();

Modified: scummvm/trunk/engines/toon/flux.cpp
===================================================================
--- scummvm/trunk/engines/toon/flux.cpp	2010-11-10 04:30:24 UTC (rev 54184)
+++ scummvm/trunk/engines/toon/flux.cpp	2010-11-10 06:22:18 UTC (rev 54185)
@@ -34,7 +34,7 @@
 	vm->getAnimationManager()->addInstance(_animationInstance);
 }
 
-CharacterFlux::~CharacterFlux(void) {
+CharacterFlux::~CharacterFlux() {
 }
 
 void CharacterFlux::playStandingAnim() {

Modified: scummvm/trunk/engines/toon/flux.h
===================================================================
--- scummvm/trunk/engines/toon/flux.h	2010-11-10 04:30:24 UTC (rev 54184)
+++ scummvm/trunk/engines/toon/flux.h	2010-11-10 06:22:18 UTC (rev 54185)
@@ -36,7 +36,7 @@
 class CharacterFlux : public Character {
 public:
 	CharacterFlux(ToonEngine *vm);
-	virtual ~CharacterFlux(void);
+	virtual ~CharacterFlux();
 
 	void setPosition(int32 x, int32 y);
 	void playStandingAnim();

Modified: scummvm/trunk/engines/toon/hotspot.cpp
===================================================================
--- scummvm/trunk/engines/toon/hotspot.cpp	2010-11-10 04:30:24 UTC (rev 54184)
+++ scummvm/trunk/engines/toon/hotspot.cpp	2010-11-10 06:22:18 UTC (rev 54185)
@@ -29,11 +29,12 @@
 namespace Toon {
 
 Hotspots::Hotspots(ToonEngine *vm) : _vm(vm) {
-	_items = 0;
+	_items = NULL;
 	_numItems = 0;
 }
 
 Hotspots::~Hotspots() {
+	delete[] _items;
 }
 
 void Hotspots::load(Common::ReadStream *Stream) {
@@ -49,7 +50,6 @@
 }
 
 void Hotspots::save(Common::WriteStream *Stream) {
-
 	Stream->writeSint16BE(_numItems);
 
 	for (int32 i = 0; i < _numItems; i++) {
@@ -123,9 +123,7 @@
 
 	_numItems = (rifsize + rifsize2) / 512;
 
-	if (_items)
-		delete[] _items;
-
+	delete[] _items;
 	_items = new HotspotData[_numItems];
 
 	// RIFs are compressed in RNC1

Modified: scummvm/trunk/engines/toon/movie.cpp
===================================================================
--- scummvm/trunk/engines/toon/movie.cpp	2010-11-10 04:30:24 UTC (rev 54184)
+++ scummvm/trunk/engines/toon/movie.cpp	2010-11-10 06:22:18 UTC (rev 54185)
@@ -56,9 +56,9 @@
 }
 
 ToonstruckSmackerDecoder::ToonstruckSmackerDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType) : Graphics::SmackerDecoder(mixer, soundType) {
-
 }
 
+// decoder is deallocated with Movie destruction i.e. new ToonstruckSmackerDecoder is needed
 Movie::Movie(ToonEngine *vm , ToonstruckSmackerDecoder *decoder) {
 	_vm = vm;
 	_playing = false;
@@ -66,6 +66,7 @@
 }
 
 Movie::~Movie() {
+	delete _decoder;
 }
 
 void Movie::init() const {

Modified: scummvm/trunk/engines/toon/resource.cpp
===================================================================
--- scummvm/trunk/engines/toon/resource.cpp	2010-11-10 04:30:24 UTC (rev 54184)
+++ scummvm/trunk/engines/toon/resource.cpp	2010-11-10 06:22:18 UTC (rev 54185)
@@ -30,6 +30,17 @@
 
 namespace Toon {
 
+Resources::Resources(ToonEngine *vm) : _vm(vm) {
+}
+
+Resources::~Resources() {
+	while(!_pakFiles.empty()) {
+		PakFile *temp = _pakFiles.back();
+		_pakFiles.pop_back();
+		delete temp;
+	}
+}
+
 void Resources::openPackage(Common::String fileName, bool preloadEntirePackage) {
 	debugC(1, kDebugResource, "openPackage(%s, %d)", fileName.c_str(), (preloadEntirePackage) ? 1 : 0);
 
@@ -39,7 +50,6 @@
 	if (!opened)
 		return;
 
-
 	PakFile *pakFile = new PakFile();
 	pakFile->open(&file, fileName, preloadEntirePackage);
 
@@ -59,10 +69,6 @@
 	}
 }
 
-Resources::Resources(ToonEngine *vm) : _vm(vm) {
-
-}
-
 uint8 *Resources::getFileData(Common::String fileName, uint32 *fileSize) {
 	debugC(4, kDebugResource, "getFileData(%s, fileSize)", fileName.c_str());
 
@@ -200,10 +206,6 @@
 	}
 }
 
-PakFile::~PakFile() {
-	close();
-}
-
 PakFile::PakFile() {
 	_bufferSize = 0;
 	_buffer = NULL;
@@ -211,4 +213,8 @@
 	_fileHandle = NULL;
 }
 
+PakFile::~PakFile() {
+	close();
+}
+
 } // End of namespace Toon

Modified: scummvm/trunk/engines/toon/resource.h
===================================================================
--- scummvm/trunk/engines/toon/resource.h	2010-11-10 04:30:24 UTC (rev 54184)
+++ scummvm/trunk/engines/toon/resource.h	2010-11-10 06:22:18 UTC (rev 54185)
@@ -58,8 +58,6 @@
 	uint32 _numFiles;
 	Common::Array<File> _files;
 	Common::File *_fileHandle;
-
-
 };
 
 class ToonEngine;
@@ -67,6 +65,7 @@
 class Resources {
 public:
 	Resources(ToonEngine *vm);
+	~Resources();
 	void openPackage(Common::String file, bool preloadEntirePackage);
 	void closePackage(Common::String fileName);
 	Common::SeekableReadStream *openFile(Common::String file);
@@ -75,7 +74,6 @@
 protected:
 	ToonEngine *_vm;
 	Common::Array<PakFile *> _pakFiles;
-
 };
 
 } // End of namespace Toon

Modified: scummvm/trunk/engines/toon/script.cpp
===================================================================
--- scummvm/trunk/engines/toon/script.cpp	2010-11-10 04:30:24 UTC (rev 54184)
+++ scummvm/trunk/engines/toon/script.cpp	2010-11-10 06:22:18 UTC (rev 54185)
@@ -72,6 +72,7 @@
 bool EMCInterpreter::callback(Common::IFFChunk &chunk) {
 	switch (chunk._type) {
 	case MKID_BE('TEXT'):
+		delete[] _scriptData->text;
 		_scriptData->text = new byte[chunk._size];
 		assert(_scriptData->text);
 		if (chunk._stream->read(_scriptData->text, chunk._size) != chunk._size)
@@ -79,6 +80,7 @@
 		break;
 
 	case MKID_BE('ORDR'):
+		delete[] _scriptData->ordr;
 		_scriptData->ordr = new uint16[chunk._size >> 1];
 		assert(_scriptData->ordr);
 		if (chunk._stream->read(_scriptData->ordr, chunk._size) != chunk._size)
@@ -89,6 +91,7 @@
 		break;
 
 	case MKID_BE('DATA'):
+		delete[] _scriptData->data;
 		_scriptData->data = new uint16[chunk._size >> 1];
 		assert(_scriptData->data);
 		if (chunk._stream->read(_scriptData->data, chunk._size) != chunk._size)
@@ -148,11 +151,13 @@
 		return;
 
 	delete[] data->text;
+	data->text = NULL;
+
 	delete[] data->ordr;
+	data->ordr = NULL;
+
 	delete[] data->data;
-
-	data->text = 0;
-	data->ordr = data->data = 0;
+	 data->data = NULL;
 }
 
 void EMCInterpreter::init(EMCState *scriptStat, const EMCData *data) {
@@ -184,7 +189,6 @@
 }
 
 bool EMCInterpreter::run(EMCState *script) {
-
 	if (script->running)
 		return false;
 
@@ -195,7 +199,6 @@
 
 	script->running = true;
 
-
 	// Should be no Problem at all to cast to uint32 here, since that's the biggest ptrdiff the original
 	// would allow, of course that's not realistic to happen to be somewhere near the limit of uint32 anyway.
 	const uint32 instOffset = (uint32)((const byte *)script->ip - (const byte *)script->dataPtr->data);

Modified: scummvm/trunk/engines/toon/script_func.cpp
===================================================================
--- scummvm/trunk/engines/toon/script_func.cpp	2010-11-10 04:30:24 UTC (rev 54184)
+++ scummvm/trunk/engines/toon/script_func.cpp	2010-11-10 06:22:18 UTC (rev 54185)
@@ -224,8 +224,9 @@
 
 ScriptFunc::~ScriptFunc(void) {
 	while(!_opcodes.empty()) {
-		//delete _opcodes.end();
+		const OpcodeV2 *temp = _opcodes.back();
 		_opcodes.pop_back();
+		delete temp;
 	}
 }
 

Modified: scummvm/trunk/engines/toon/text.cpp
===================================================================
--- scummvm/trunk/engines/toon/text.cpp	2010-11-10 04:30:24 UTC (rev 54184)
+++ scummvm/trunk/engines/toon/text.cpp	2010-11-10 06:22:18 UTC (rev 54185)
@@ -27,14 +27,13 @@
 
 namespace Toon {
 
-
 TextResource::TextResource(ToonEngine *vm) : _vm(vm) {
 	_numTexts = 0;
-	_textData = 0;
+	_textData = NULL;
 }
 
 TextResource::~TextResource(void) {
-
+	delete[] _textData;
 }
 
 bool TextResource::loadTextResource(Common::String fileName) {
@@ -45,6 +44,7 @@
 	if (!data)
 		return false;
 
+	delete[] _textData;
 	_textData = new uint8[fileSize];
 	memcpy(_textData, data, fileSize);
 	_numTexts = READ_LE_UINT16(data);

Modified: scummvm/trunk/engines/toon/toon.cpp
===================================================================
--- scummvm/trunk/engines/toon/toon.cpp	2010-11-10 04:30:24 UTC (rev 54184)
+++ scummvm/trunk/engines/toon/toon.cpp	2010-11-10 06:22:18 UTC (rev 54185)
@@ -105,7 +105,7 @@
 	resources()->openPackage("misc/drew.pak", true);
 
 	for (int32 i = 0; i < 32; i++)
-		_characters[i] = 0;
+		_characters[i] = NULL;
 
 	_characters[0] = new CharacterDrew(this);
 	_characters[1] = new CharacterFlux(this);
@@ -737,10 +737,8 @@
 	: Engine(syst), _gameDescription(gameDescription), _language(gameDescription->language) {
 	_system = syst;
 	_tickLength = 16;
-	_currentMask = 0;
-	_currentPicture = 0;
-	_roomScaleData = 0;
-	_shadowLUT = 0;
+	_currentPicture = NULL;
+	_currentMask = NULL;
 	_showConversationText = true;
 	_isDemo = _gameDescription->flags & ADGF_DEMO;
 
@@ -757,6 +755,8 @@
 	DebugMan.addDebugChannel(kDebugTools, "Tools", "Tools debug level");
 	DebugMan.addDebugChannel(kDebugText, "Text", "Text debug level");
 
+	_resources = NULL;
+	_animationManager = NULL;
 	_moviePlayer = NULL;
 	_mainSurface = NULL;
 
@@ -768,6 +768,9 @@
 	_universalPalette = NULL;
 	_fluxPalette = NULL;
 
+	_roomScaleData = NULL;
+	_shadowLUT = NULL;
+
 	_conversationData = NULL;
 
 	_fontRenderer = NULL;
@@ -778,9 +781,20 @@
 	_roomTexts = NULL;
 	_script_func = NULL;
 	_script = NULL;
+
+	_saveBufferStream = NULL;
+
 	_pathFinding = NULL;
 	_console = new ToonConsole(this);
 
+	_cursorAnimation = NULL;
+	_cursorAnimationInstance = NULL;
+	_dialogIcons = NULL;
+	_inventoryIcons = NULL;
+	_inventoryIconSlots = NULL;
+	_genericTexts = NULL;
+	_audioManager = NULL;
+
 	switch (_language) {
 	case Common::EN_GRB:
 	case Common::EN_USA:
@@ -807,6 +821,11 @@
 }
 
 ToonEngine::~ToonEngine() {
+	delete _currentPicture;
+	delete _currentMask;
+
+	delete _resources;
+	delete _animationManager;
 	delete _moviePlayer;
 	delete _mainSurface;
 
@@ -818,6 +837,9 @@
 	delete[] _universalPalette;
 	delete[] _fluxPalette;
 
+	delete[] _roomScaleData;
+	delete[] _shadowLUT;
+
 	delete[] _conversationData;
 
 	delete _fontRenderer;
@@ -829,8 +851,21 @@
 	delete _script_func;
 	delete _script;
 
+	delete _saveBufferStream;
+
 	delete _pathFinding;
 
+	for (int32 i = 0; i < 32; i++)
+		delete _characters[i];
+
+	delete _cursorAnimation;
+	delete _cursorAnimationInstance;
+	delete _dialogIcons;
+	delete _inventoryIcons;
+	delete _inventoryIconSlots;
+	//delete _genericTexts;
+	//delete _audioManager;
+
 	DebugMan.clearAllDebugChannels();
 	delete _console;
 }
@@ -940,7 +975,6 @@
 	char temp[256];
 	char temp2[256];
 
-
 	_firstFrame = true;
 
 	_gameState->_lastVisitedScene = _gameState->_currentScene;
@@ -1002,7 +1036,6 @@
 	_mouseButton = 0;
 	_lastMouseButton = 0x3;
 
-
 	// load package
 	strcpy(temp, createRoomFilename(Common::String::format("%s.pak", _gameState->_locations[_gameState->_currentScene]._name).c_str()).c_str());
 	resources()->openPackage(temp, true);
@@ -1022,27 +1055,30 @@
 	// load artwork
 	strcpy(temp, state()->_locations[SceneId]._name);
 	strcat(temp, ".cps");
+	delete _currentPicture;
 	_currentPicture = new Picture(this);
 	_currentPicture->loadPicture(temp);
 	_currentPicture->setupPalette();
 
 	strcpy(temp, state()->_locations[SceneId]._name);
 	strcat(temp, ".msc");
+	delete _currentMask;
 	_currentMask = new Picture(this);
 	if (_currentMask->loadPicture(temp))
 		_pathFinding->init(_currentMask);
 
 	strcpy(temp, state()->_locations[SceneId]._name);
 	strcat(temp, ".tre");
+	delete _roomTexts;
 	_roomTexts = new TextResource(this);
 	_roomTexts->loadTextResource(temp);
 
-
 	strcpy(temp, state()->_locations[SceneId]._name);
 	strcat(temp, ".dat");
 	uint32 fileSize;
 	uint8 *sceneData = resources()->getFileData(temp, &fileSize);
 	if (sceneData) {
+		delete[] _roomScaleData;
 		_roomScaleData = new uint8[fileSize];
 		memcpy(_roomScaleData, sceneData, fileSize);
 	}
@@ -1068,7 +1104,6 @@
 	_hotspots->LoadRif(temp, temp2);
 	restoreRifFlags(_gameState->_currentScene);
 
-
 	strcpy(temp, state()->_locations[SceneId]._name);
 	strcat(temp, ".cnv");
 	uint32 convfileSize;
@@ -1090,7 +1125,6 @@
 	_drew->update(0);
 	_flux->update(0);
 
-
 	_script->load(temp, &_scriptData, &_script_func->_opcodes);
 	_script->init(&_scriptState[0], &_scriptData);
 	_script->init(&_scriptState[1], &_scriptData);
@@ -1124,7 +1158,6 @@
 	_lastProcessedSceneScript = 0;
 	_gameState->_locations[SceneId]._visited = true;
 
-
 	setupGeneralPalette();
 	createShadowLUT();
 
@@ -1224,8 +1257,10 @@
 }
 
 void ToonEngine::loadCursor() {
+	delete _cursorAnimation;
 	_cursorAnimation = new Animation(this);
 	_cursorAnimation->loadAnimation("MOUSE.CAF");
+	delete _cursorAnimationInstance;
 	_cursorAnimationInstance = _animationManager->createNewInstance(kAnimationCursor);
 	_cursorAnimationInstance->setAnimation(_cursorAnimation);
 	_cursorAnimationInstance->setVisible(true);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list