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

sylvaintv at users.sourceforge.net sylvaintv at users.sourceforge.net
Fri Nov 12 23:31:05 CET 2010


Revision: 54219
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54219&view=rev
Author:   sylvaintv
Date:     2010-11-12 22:31:04 +0000 (Fri, 12 Nov 2010)

Log Message:
-----------
TOON: Fix audio crashs and more memory leaks

Modified Paths:
--------------
    scummvm/trunk/engines/toon/anim.cpp
    scummvm/trunk/engines/toon/audio.cpp
    scummvm/trunk/engines/toon/movie.cpp
    scummvm/trunk/engines/toon/movie.h
    scummvm/trunk/engines/toon/resource.cpp
    scummvm/trunk/engines/toon/resource.h
    scummvm/trunk/engines/toon/toon.cpp
    scummvm/trunk/engines/toon/toon.h

Modified: scummvm/trunk/engines/toon/anim.cpp
===================================================================
--- scummvm/trunk/engines/toon/anim.cpp	2010-11-12 18:05:23 UTC (rev 54218)
+++ scummvm/trunk/engines/toon/anim.cpp	2010-11-12 22:31:04 UTC (rev 54219)
@@ -108,7 +108,7 @@
 		}
 	}
 
-	//delete[] fileData;
+	_vm->resources()->purgeFileData();
 	delete[] finalBuffer;
 	return true;
 }

Modified: scummvm/trunk/engines/toon/audio.cpp
===================================================================
--- scummvm/trunk/engines/toon/audio.cpp	2010-11-12 18:05:23 UTC (rev 54218)
+++ scummvm/trunk/engines/toon/audio.cpp	2010-11-12 22:31:04 UTC (rev 54219)
@@ -64,6 +64,7 @@
 }
 
 AudioManager::~AudioManager(void) {
+	_mixer->stopAll();
 	for (int32 i = 0; i < 4; i++) {
 		closeAudioPack(i);
 	}
@@ -130,7 +131,7 @@
 		_currentMusicChannel = 0;
 	}
 
-	delete _channels[_currentMusicChannel];
+	// no need to delete instance here it will automatically deleted by the mixer is done with it
 	_channels[_currentMusicChannel] = new AudioStreamInstance(this, _mixer, srs, true);
 	_channels[_currentMusicChannel]->setVolume(_musicMuted ? 0 : 255);
 	_channels[_currentMusicChannel]->play(true, Audio::Mixer::kMusicSoundType);
@@ -157,7 +158,7 @@
 	else
 		stream = _audioPacks[1]->getStream(id);
 
-	delete _channels[2];
+	// no need to delete channel 2, it will be deleted by the mixer when the stream is finished
 	_channels[2] = new AudioStreamInstance(this, _mixer, stream);
 	_channels[2]->play(false, Audio::Mixer::kSpeechSoundType);
 	_channels[2]->setVolume(_voiceMuted ? 0 : 255);
@@ -278,6 +279,9 @@
 int AudioStreamInstance::readBuffer(int16 *buffer, const int numSamples) {
 	debugC(5, kDebugAudio, "readBuffer(buffer, %d)", numSamples);
 
+	if(_stopped) 
+		return 0;
+
 	handleFade(numSamples);
 	int32 leftSamples = numSamples;
 	int32 destOffset = 0;

Modified: scummvm/trunk/engines/toon/movie.cpp
===================================================================
--- scummvm/trunk/engines/toon/movie.cpp	2010-11-12 18:05:23 UTC (rev 54218)
+++ scummvm/trunk/engines/toon/movie.cpp	2010-11-12 22:31:04 UTC (rev 54219)
@@ -46,7 +46,10 @@
 		if (forcedflags & 0x10 || _surface->h == 200) {
 
 			_header.flags = 4;
-			delete this->_surface;
+			if (_surface) {
+				_surface->free();
+				delete _surface;
+			}
 			_surface = new Graphics::Surface();
 			_surface->create(640, 400, 1);
 		}

Modified: scummvm/trunk/engines/toon/movie.h
===================================================================
--- scummvm/trunk/engines/toon/movie.h	2010-11-12 18:05:23 UTC (rev 54218)
+++ scummvm/trunk/engines/toon/movie.h	2010-11-12 22:31:04 UTC (rev 54219)
@@ -34,6 +34,7 @@
 class ToonstruckSmackerDecoder : public Graphics::SmackerDecoder {
 public:
 	ToonstruckSmackerDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType = Audio::Mixer::kSFXSoundType);
+	virtual ~ToonstruckSmackerDecoder() {}
 	void handleAudioTrack(byte track, uint32 chunkSize, uint32 unpackedSize);
 	bool loadFile(const Common::String &filename, int forcedflags) ;
 };
@@ -41,7 +42,7 @@
 class Movie {
 public:
 	Movie(ToonEngine *vm, ToonstruckSmackerDecoder *decoder);
-	~Movie(void);
+	virtual ~Movie(void);
 
 	void init() const;
 	void play(Common::String video, int32 flags = 0);

Modified: scummvm/trunk/engines/toon/resource.cpp
===================================================================
--- scummvm/trunk/engines/toon/resource.cpp	2010-11-12 18:05:23 UTC (rev 54218)
+++ scummvm/trunk/engines/toon/resource.cpp	2010-11-12 22:31:04 UTC (rev 54219)
@@ -39,6 +39,8 @@
 		_pakFiles.pop_back();
 		delete temp;
 	}
+
+	purgeFileData();
 }
 
 void Resources::openPackage(Common::String fileName, bool preloadEntirePackage) {
@@ -84,6 +86,7 @@
 		uint8 *memory = (uint8 *)new uint8[*fileSize];
 		file.read(memory, *fileSize);
 		file.close();
+		_allocatedFileData.push_back(memory);
 		return memory;
 	} else {
 		for (uint32 i = 0; i < _pakFiles.size(); i++) {
@@ -124,6 +127,13 @@
 		return 0;
 	}
 }
+
+void Resources::purgeFileData() {
+	for (uint32 i = 0; i < _allocatedFileData.size(); i++) {
+		delete[] _allocatedFileData[i];
+	}
+	_allocatedFileData.clear();
+}
 Common::SeekableReadStream *PakFile::createReadStream(Common::String fileName) {
 	debugC(1, kDebugResource, "createReadStream(%s)", fileName.c_str());
 

Modified: scummvm/trunk/engines/toon/resource.h
===================================================================
--- scummvm/trunk/engines/toon/resource.h	2010-11-12 18:05:23 UTC (rev 54218)
+++ scummvm/trunk/engines/toon/resource.h	2010-11-12 22:31:04 UTC (rev 54219)
@@ -69,10 +69,12 @@
 	void openPackage(Common::String file, bool preloadEntirePackage);
 	void closePackage(Common::String fileName);
 	Common::SeekableReadStream *openFile(Common::String file);
-	uint8 *getFileData(Common::String fileName, uint32 *fileSize);
+	uint8 *getFileData(Common::String fileName, uint32 *fileSize); // this memory must be copied to your own structures!
+	void purgeFileData();
 
 protected:
 	ToonEngine *_vm;
+	Common::Array<uint8 *> _allocatedFileData;
 	Common::Array<PakFile *> _pakFiles;
 };
 

Modified: scummvm/trunk/engines/toon/toon.cpp
===================================================================
--- scummvm/trunk/engines/toon/toon.cpp	2010-11-12 18:05:23 UTC (rev 54218)
+++ scummvm/trunk/engines/toon/toon.cpp	2010-11-12 22:31:04 UTC (rev 54219)
@@ -793,8 +793,10 @@
 	_inventoryIcons = NULL;
 	_inventoryIconSlots = NULL;
 	_genericTexts = NULL;
-	_audioManager = NULL;
+	_audioManager = NULL; 
 
+	memset(&_scriptData, 0, sizeof(EMCData));
+
 	switch (_language) {
 	case Common::EN_GRB:
 	case Common::EN_USA:
@@ -849,6 +851,8 @@
 	delete _genericTexts;
 	delete _roomTexts;
 	delete _script_func;
+
+	_script->unload(&_scriptData);
 	delete _script;
 
 	delete _saveBufferStream;
@@ -864,8 +868,10 @@
 	delete _inventoryIcons;
 	delete _inventoryIconSlots;
 	//delete _genericTexts;
-	//delete _audioManager;
+	delete _audioManager;
 
+	unloadToonDat();
+
 	DebugMan.clearAllDebugChannels();
 	delete _console;
 }
@@ -1125,6 +1131,7 @@
 	_drew->update(0);
 	_flux->update(0);
 
+	_script->unload(&_scriptData);
 	_script->load(temp, &_scriptData, &_script_func->_opcodes);
 	_script->init(&_scriptState[0], &_scriptData);
 	_script->init(&_scriptState[1], &_scriptData);
@@ -1252,6 +1259,8 @@
 	while (_script->run(&status))
 		waitForScriptStep();
 
+	_script->unload(&data);
+
 	setupGeneralPalette();
 
 }
@@ -4517,14 +4526,20 @@
 
 	_numVariant = in.readUint16BE();
 
-	_locationDirNotVisited = loadTextsVariante(in);
-	_locationDirVisited = loadTextsVariante(in);
-	_specialInfoLine = loadTextsVariante(in);
+	_locationDirNotVisited = loadTextsVariants(in);
+	_locationDirVisited = loadTextsVariants(in);
+	_specialInfoLine = loadTextsVariants(in);
 
 	return true;
 }
 
-char **ToonEngine::loadTextsVariante(Common::File &in) {
+void ToonEngine::unloadToonDat() {
+	unloadTextsVariants(_locationDirNotVisited);
+	unloadTextsVariants(_locationDirVisited);
+	unloadTextsVariants(_specialInfoLine);
+}
+
+char **ToonEngine::loadTextsVariants(Common::File &in) {
 	int  numTexts;
 	int  entryLen;
 	int  len;
@@ -4560,6 +4575,14 @@
 	return res;
 }
 
+void ToonEngine::unloadTextsVariants(char **texts) {
+	if (!texts)
+		return;
+
+	free(*texts - DATAALIGNMENT);
+	free(texts);
+}
+
 void ToonEngine::makeLineNonWalkable(int32 x, int32 y, int32 x2, int32 y2) {
 	_currentMask->drawLineOnMask(x, y, x2, y2, false);
 }

Modified: scummvm/trunk/engines/toon/toon.h
===================================================================
--- scummvm/trunk/engines/toon/toon.h	2010-11-12 18:05:23 UTC (rev 54218)
+++ scummvm/trunk/engines/toon/toon.h	2010-11-12 22:31:04 UTC (rev 54219)
@@ -106,7 +106,9 @@
 	bool showMainmenu(bool &loadedGame);
 	void init();
 	bool loadToonDat();
-	char **loadTextsVariante(Common::File &in);
+	char **loadTextsVariants(Common::File &in);
+	void unloadTextsVariants(char **texts);
+	void unloadToonDat();
 	void setPaletteEntries(uint8 *palette, int32 offset, int32 num);
 	void fixPaletteEntries(uint8 *palette, int num);
 	void flushPalette();
@@ -200,6 +202,8 @@
 	void waitForScriptStep();
 	void doMagnifierEffect();
 
+
+
 	bool canSaveGameStateCurrently();
 	bool canLoadGameStateCurrently();
 	void pauseEngineIntern(bool pause);


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