[Scummvm-cvs-logs] SF.net SVN: scummvm: [22790] scummvm/trunk/engines/gob

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Wed May 31 01:47:11 CEST 2006


Revision: 22790
Author:   drmccoy
Date:     2006-05-31 01:44:14 -0700 (Wed, 31 May 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22790&view=rev

Log Message:
-----------
- Removed usage of OSystem::quit(), added a _quitRequested variable
- Fixed some leaks, unitialized memory and delete/delete[]-errors

Modified Paths:
--------------
    scummvm/trunk/engines/gob/game.cpp
    scummvm/trunk/engines/gob/game.h
    scummvm/trunk/engines/gob/game_v1.cpp
    scummvm/trunk/engines/gob/game_v2.cpp
    scummvm/trunk/engines/gob/gob.cpp
    scummvm/trunk/engines/gob/gob.h
    scummvm/trunk/engines/gob/goblin.cpp
    scummvm/trunk/engines/gob/goblin.h
    scummvm/trunk/engines/gob/goblin_v1.cpp
    scummvm/trunk/engines/gob/init.cpp
    scummvm/trunk/engines/gob/inter.cpp
    scummvm/trunk/engines/gob/inter_v1.cpp
    scummvm/trunk/engines/gob/inter_v2.cpp
    scummvm/trunk/engines/gob/map_v1.cpp
    scummvm/trunk/engines/gob/mult.cpp
    scummvm/trunk/engines/gob/mult.h
    scummvm/trunk/engines/gob/mult_v1.cpp
    scummvm/trunk/engines/gob/mult_v2.cpp
    scummvm/trunk/engines/gob/music.cpp
    scummvm/trunk/engines/gob/music.h
    scummvm/trunk/engines/gob/util.cpp
    scummvm/trunk/engines/gob/video.cpp
Modified: scummvm/trunk/engines/gob/game.cpp
===================================================================
--- scummvm/trunk/engines/gob/game.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/game.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -132,6 +132,28 @@
 	_dword_2F2B6 = 0;
 }
 
+Game::~Game() {
+	if (_imdFile) {
+		if (_imdFile->palette)
+			delete[] _imdFile->palette;
+		if (_imdFile->surfDesc &&
+				(_imdFile->surfDesc != _vm->_draw->_spritesArray[20]) &&
+				(_imdFile->surfDesc != _vm->_draw->_spritesArray[21]))
+			_vm->_video->freeSurfDesc(_imdFile->surfDesc);
+		if (_imdFile->framesPos)
+			delete[] _imdFile->framesPos;
+		if (_imdFile->frameCoords)
+			delete[] _imdFile->frameCoords;
+		delete _imdFile;
+	}
+	if (_imdFrameData)
+		delete[] _imdFrameData;
+	if (_imdVidBuffer)
+		delete[] _imdVidBuffer;
+	if (_word_2FC80)
+		delete[] _word_2FC80;
+}
+
 char *Game::loadExtData(int16 itemId, int16 *pResWidth, int16 *pResHeight) {
 	int16 commonHandle;
 	int16 itemsCount;
@@ -376,7 +398,7 @@
 	if (slot == -1)
 		slot = _vm->_parse->parseValExpr();
 
-	if (_soundSamples[slot] == 0)
+	if ((slot < 0) || (slot >= 60) || (_soundSamples[slot] == 0))
 		return;
 
 	char* data = _soundSamples[slot]->data;
@@ -1221,7 +1243,7 @@
 		WRITE_VAR(16, 0);
 		_activeCollResId = 0;
 	}
-	while (_activeCollResId == 0 && !_vm->_inter->_terminate);
+	while (_activeCollResId == 0 && !_vm->_inter->_terminate && !_vm->_quitRequested);
 
 	if (((uint16)_activeCollResId & ~0x8000) == collResId) {
 		_collStackPos = 0;
@@ -2216,6 +2238,8 @@
 
 	// To allow quitting, etc. during IMDs
 	_vm->_util->processInput();
+	if (_vm->_quitRequested) 
+		return;
 
 	if (byte_31344 != 2) {
 		if (var_4 & 0x800) {

Modified: scummvm/trunk/engines/gob/game.h
===================================================================
--- scummvm/trunk/engines/gob/game.h	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/game.h	2006-05-31 08:44:14 UTC (rev 22790)
@@ -179,7 +179,7 @@
 	byte *_word_2FC80;
 
 	Game(GobEngine *vm);
-	virtual ~Game() {};
+	virtual ~Game();
 
 	char *loadExtData(int16 dataId, int16 *pResWidth, int16 *pResHeight);
 	char *loadTotResource(int16 id);

Modified: scummvm/trunk/engines/gob/game_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/game_v1.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/game_v1.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -72,7 +72,7 @@
 	strcpy(savedTotName, _curTotFile);
 
 	if (skipPlay == 0) {
-		while (1) {
+		while (!_vm->_quitRequested) {
 			for (i = 0; i < 4; i++) {
 				_vm->_draw->_fontToSprite[i].sprite = -1;
 				_vm->_draw->_fontToSprite[i].base = -1;

Modified: scummvm/trunk/engines/gob/game_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/game_v2.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/game_v2.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -72,7 +72,7 @@
 	strcpy(savedTotName, _curTotFile);
 
 	if (skipPlay == 0) {
-		while (1) {
+		while (!_vm->_quitRequested) {
 			for (i = 0; i < 4; i++) {
 				_vm->_draw->_fontToSprite[i].sprite = -1;
 				_vm->_draw->_fontToSprite[i].base = -1;
@@ -422,7 +422,7 @@
 
 	timeKey = _vm->_util->getTimeKey();
 	while (1) {
-		if (_vm->_inter->_terminate) {
+		if (_vm->_inter->_terminate || _vm->_quitRequested) {
 			if (handleMouse)
 				_vm->_draw->blitCursor();
 			return 0;

Modified: scummvm/trunk/engines/gob/gob.cpp
===================================================================
--- scummvm/trunk/engines/gob/gob.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/gob.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -141,6 +141,7 @@
 	_features = features;
 	_language = lang;
 	_copyProtection = ConfMan.getBool("copy_protection");
+	_quitRequested = false;
 
 	Common::addSpecialDebugLevel(DEBUG_FUNCOP, "FuncOpcodes", "Script FuncOpcodes debug level");
 	Common::addSpecialDebugLevel(DEBUG_DRAWOP, "DrawOpcodes", "Script DrawOpcodes debug level");
@@ -173,7 +174,6 @@
 	delete _scenery;
 	delete _gtimer;
 	delete _util;
-	delete _inter;
 	delete _music;
 }
 
@@ -188,7 +188,7 @@
 }
 
 void GobEngine::shutdown() {
-	_system->quit();
+	_quitRequested = true;
 }
 
 int GobEngine::init() {

Modified: scummvm/trunk/engines/gob/gob.h
===================================================================
--- scummvm/trunk/engines/gob/gob.h	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/gob.h	2006-05-31 08:44:14 UTC (rev 22790)
@@ -98,6 +98,7 @@
 	int32 _features;
 	Common::Language _language;
 	bool _copyProtection;
+	bool _quitRequested;
 
 	Game *_game;
 	Snd *_snd;

Modified: scummvm/trunk/engines/gob/goblin.cpp
===================================================================
--- scummvm/trunk/engines/gob/goblin.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/goblin.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -161,6 +161,45 @@
 	_dword_2F9B2 = 0;
 }
 
+Goblin::~Goblin() {
+	int i, state, col;
+
+	if (_objList)
+		_vm->_util->deleteList(_objList);
+
+	for (i = 0; i < 4; i++) {
+		if (_goblins[i]) {
+			if (_goblins[i]->stateMach) {
+				for (state = 0; state < (i == 3 ? 70 : 40); state++)
+					for (col = 0; col < 6; col++)
+						if (_goblins[i]->stateMach[state][col])
+							delete _goblins[i]->stateMach[state][col];
+				delete _goblins[i]->stateMach;
+			}
+			delete _goblins[i];
+		}
+	}
+	for (i = 0; i < 20; i++) {
+		if (_objects[i]) {
+			if (_objects[i]->stateMach) {
+				for (state = 0; state < 40; state++)
+					for (col = 0; col < 6; col++)
+						if (_objects[i]->stateMach[state][col])
+							delete _objects[i]->stateMach[state][col];
+				delete _objects[i]->stateMach;
+			}
+			delete _objects[i];
+		}
+	}
+
+	for (i = 0; i < 16; i++)
+		if (_soundData[i]) {
+			if (_soundData[i]->data)
+				delete[] _soundData[i]->data;
+			delete _soundData[i];
+		}
+}
+
 char Goblin::rotateState(int16 from, int16 to) {
 	return _rotStates[from / 2][to / 2];
 }

Modified: scummvm/trunk/engines/gob/goblin.h
===================================================================
--- scummvm/trunk/engines/gob/goblin.h	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/goblin.h	2006-05-31 08:44:14 UTC (rev 22790)
@@ -226,7 +226,7 @@
 	virtual void initiateMove(int16 index) = 0;
 
 	Goblin(GobEngine *vm);
-	virtual ~Goblin() {};
+	virtual ~Goblin();
 
 protected:
 	int16 _rotStates[4][4];

Modified: scummvm/trunk/engines/gob/goblin_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/goblin_v1.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/goblin_v1.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -143,7 +143,7 @@
 	_vm->_map->findNearestToGob(0);
 	_vm->_map->optimizePoints(0, 0, 0);
 
-	_pathExistence = _vm->_map->checkDirectPath(0, _vm->_map->_curGoblinX, _vm->_map->_curGoblinY,
+	_pathExistence = _vm->_map->checkDirectPath(-1, _vm->_map->_curGoblinX, _vm->_map->_curGoblinY,
 	    _pressedMapX, _pressedMapY);
 
 	if (_pathExistence == 3) {

Modified: scummvm/trunk/engines/gob/init.cpp
===================================================================
--- scummvm/trunk/engines/gob/init.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/init.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -81,12 +81,10 @@
 	_vm->_dataio->closeDataFile();
 
 	if (_vm->_global->_sprAllocated != 0)
-		error("cleanup: Error! Allocated sprites left: %d",
-		    _vm->_global->_sprAllocated);
+		warning("cleanup: Allocated sprites left: %d", _vm->_global->_sprAllocated);
 
 	_vm->_snd->stopSound(0);
 	_vm->_util->keyboard_release();
-	g_system->quit();
 }
 
 void Init::initGame(char *totName) {

Modified: scummvm/trunk/engines/gob/inter.cpp
===================================================================
--- scummvm/trunk/engines/gob/inter.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/inter.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -168,6 +168,9 @@
 		if (executeFuncOpcode(cmd2, cmd, cmdCount, counter, retFlag))
 			return;
 
+		if (_vm->_quitRequested)
+			break;
+
 		if (_breakFlag) {
 			if (retFlag != 2)
 				break;
@@ -263,7 +266,7 @@
 
 void Inter::callSub(int16 retFlag) {
 	int16 block;
-	while (_vm->_global->_inter_execPtr != 0 && (char *)_vm->_global->_inter_execPtr != _vm->_game->_totFileData) {
+	while (!_vm->_quitRequested && _vm->_global->_inter_execPtr != 0 && (char *)_vm->_global->_inter_execPtr != _vm->_game->_totFileData) {
 		block = *_vm->_global->_inter_execPtr;
 		if (block == 1) {
 			funcBlock(retFlag);

Modified: scummvm/trunk/engines/gob/inter_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/inter_v1.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/inter_v1.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -1421,7 +1421,7 @@
 		funcBlock(1);
 		_vm->_global->_inter_execPtr = blockPtr + size + 1;
 		flag = evalBoolResult();
-	} while (flag == 0 && !_breakFlag && !_terminate);
+	} while (flag == 0 && !_breakFlag && !_terminate && !_vm->_quitRequested);
 
 	_nestLevel[0]--;
 
@@ -1457,7 +1457,7 @@
 			_vm->_global->_inter_execPtr += size;
 		}
 
-		if (_breakFlag || _terminate) {
+		if (_breakFlag || _terminate || _vm->_quitRequested) {
 			_vm->_global->_inter_execPtr = blockPtr;
 			_vm->_global->_inter_execPtr += size;
 			break;
@@ -1525,7 +1525,9 @@
 
 	if (_vm->_mult->_objects == 0) {
 		_vm->_mult->_renderData = new int16[_vm->_mult->_objCount * 9];
+		memset(_vm->_mult->_renderData, 0, _vm->_mult->_objCount * 9 * sizeof(int16));
 		_vm->_mult->_objects = new Mult::Mult_Object[_vm->_mult->_objCount];
+		memset(_vm->_mult->_objects, 0, _vm->_mult->_objCount * sizeof(Mult::Mult_Object));
 
 		for (i = 0; i < _vm->_mult->_objCount; i++) {
 			_vm->_mult->_objects[i].pPosX = (int32 *)(_vm->_global->_inter_variables + i * 4 + (posXVar / 4) * 4);

Modified: scummvm/trunk/engines/gob/inter_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/inter_v2.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/inter_v2.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -865,7 +865,7 @@
 			_vm->_game->_soundSamples[slot] = _vm->_game->loadSND(sndfile, 3);
 		} else {
 			strcat(sndfile, ".ADL");
-			// TODO: This is very ugly
+			// TODO: This is very ugly (and doesn't work with Snd::freeSoundDesc())
 			_vm->_game->_soundSamples[slot] = (Snd::SoundDesc *) _vm->_dataio->getData(sndfile);
 		}
 		_vm->_game->_soundTypes[slot] = 2;
@@ -899,7 +899,7 @@
 				if (!isADL)
 					_vm->_game->loadSound(slot, extData);
 				else
-					// TODO: This is very ugly
+					// TODO: This is very ugly (and doesn't work with Snd::freeSoundDesc())
 					_vm->_game->_soundSamples[slot] = (Snd::SoundDesc *) extData;
 			}
 		} else { // loc_9A13
@@ -907,7 +907,7 @@
 			if (!isADL)
 				_vm->_game->loadSound(slot, extData);
 			else
-				// TODO: This is very ugly
+				// TODO: This is very ugly (and doesn't work with Snd::freeSoundDesc())
 				_vm->_game->_soundSamples[slot] = (Snd::SoundDesc *) extData;
 		}
 	}
@@ -1466,11 +1466,15 @@
 
 	if (_vm->_mult->_objects == 0) {
 		_vm->_mult->_renderData2 = new Mult::Mult_Object*[_vm->_mult->_objCount];
+		memset(_vm->_mult->_renderData2, 0, _vm->_mult->_objCount * sizeof(Mult::Mult_Object*));
 		_vm->_mult->_renderData = new int16[_vm->_mult->_objCount * 9];
+		memset(_vm->_mult->_renderData, 0, _vm->_mult->_objCount * 9 * sizeof(int16));
 		if (_vm->_inter->_terminate)
 			return;
 		_vm->_mult->_orderArray = new int8[_vm->_mult->_objCount];
+		memset(_vm->_mult->_orderArray, 0, _vm->_mult->_objCount * sizeof(int8));
 		_vm->_mult->_objects = new Mult::Mult_Object[_vm->_mult->_objCount];
+		memset(_vm->_mult->_objects, 0, _vm->_mult->_objCount * sizeof(Mult::Mult_Object));
 
 		for (i = 0; i < _vm->_mult->_objCount; i++) {
 			_vm->_mult->_objects[i].pPosX = (int32 *)(_vm->_global->_inter_variables + i * 4 + (posXVar / 4) * 4);

Modified: scummvm/trunk/engines/gob/map_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/map_v1.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/map_v1.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -61,7 +61,20 @@
 }
 
 Map_v1::~Map_v1() {
-	delete[] _passMap;
+	int i;
+
+	_mapWidth = 26;
+	_mapHeight = 28;
+
+	if (_passMap)
+		delete[] _passMap;
+	if (_itemsMap) {
+		for (i = 0; i < _mapHeight; i++)
+			delete[] _itemsMap[i];
+		delete[] _itemsMap;
+	}
+	if (_wayPoints)
+		delete[] _wayPoints;
 }
 
 void Map_v1::loadMapObjects(char *avjFile) {
@@ -157,10 +170,14 @@
 		_vm->_goblin->_goblins[i]->state = READ_LE_UINT16(savedPtr2);
 		savedPtr2 += 2;
 
-		if (i == 3)
+		if (i == 3) {
 			_vm->_goblin->_goblins[i]->stateMach = new Goblin::Gob_StateLine[70];
-		else
+			memset(_vm->_goblin->_goblins[i]->stateMach, 0, 70 * sizeof(Goblin::Gob_StateLine));
+		}
+		else {
 			_vm->_goblin->_goblins[i]->stateMach = new Goblin::Gob_StateLine[40];
+			memset(_vm->_goblin->_goblins[i]->stateMach, 0, 40 * sizeof(Goblin::Gob_StateLine));
+		}
 
 		uint32* tempstatedata = new uint32[40*6];
 		for (state = 0; state < 40; ++state) {

Modified: scummvm/trunk/engines/gob/mult.cpp
===================================================================
--- scummvm/trunk/engines/gob/mult.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/mult.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -145,9 +145,11 @@
 
 	delete[] _objects;
 	delete[] _renderData;
+	delete[] _orderArray;
 
 	_objects = 0;
 	_renderData = 0;
+	_orderArray = 0;
 	_vm->_anim->_animSurf = 0;
 }
 

Modified: scummvm/trunk/engines/gob/mult.h
===================================================================
--- scummvm/trunk/engines/gob/mult.h	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/mult.h	2006-05-31 08:44:14 UTC (rev 22790)
@@ -323,7 +323,7 @@
 	Mult_Data *_multDatas[8];
 
 	Mult_v2(GobEngine *vm);
-	virtual ~Mult_v2() {};
+	virtual ~Mult_v2();
 
 	virtual void setMultData(uint16 multindex);
 	virtual void multSub(uint16 multindex);

Modified: scummvm/trunk/engines/gob/mult_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/mult_v1.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/mult_v1.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -244,12 +244,15 @@
 			_objCount = 4;
 
 			_objects = new Mult_Object[_objCount];
+			memset(_objects, 0, _objCount * sizeof(Mult_Object));
 			_renderData = new int16[9 * _objCount];
+			memset(_renderData, 0, _objCount * 9 * sizeof(int16));
 
 			_animArrayX = new int32[_objCount];
 			_animArrayY = new int32[_objCount];
 
 			_animArrayData = new Mult_AnimData[_objCount];
+			memset(_animArrayData, 0, _objCount * sizeof(Mult_AnimData));
 
 			for (_counter = 0; _counter < _objCount; _counter++) {
 				multObj = &_objects[_counter];
@@ -319,7 +322,7 @@
 
 		_frame++;
 		_vm->_util->waitEndFrame();
-	} while (stop == 0 && stopNoClear == 0);
+	} while (stop == 0 && stopNoClear == 0 && !_vm->_quitRequested);
 
 	if (stopNoClear == 0) {
 		if (_animDataAllocated) {

Modified: scummvm/trunk/engines/gob/mult_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/mult_v2.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/mult_v2.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -44,6 +44,21 @@
 	for (i = 0; i < 8; i++) _multDatas[i] = 0;
 }
 
+Mult_v2::~Mult_v2() {
+	int i;
+
+	freeMultKeys();
+	for (i = 0; i < 8; i++) {
+		_multData2 = _multDatas[i];
+		freeMultKeys();
+	}
+
+	if (_orderArray)
+		delete[] _orderArray;
+	if (_renderData2)
+		delete[] _renderData2;
+}
+
 void Mult_v2::loadMult(int16 resId) {
 	int16 i, j;
 	int8 index;
@@ -57,6 +72,7 @@
 	index = (resId & 0x8000) ? *_vm->_global->_inter_execPtr++ : 0;
 
 	_multData2 = new Mult_Data;
+	memset(_multData2, 0, sizeof(Mult_Data));
 
 	// ---.
 	for (i = 0; i < 4; i++) {
@@ -372,11 +388,24 @@
 			_vm->_anim->_areaHeight = 200;
 			_objCount = 4;
 
+			if (_objects)
+				delete[] _objects;
+			if (_orderArray)
+				delete[] _orderArray;
+			if (_renderData)
+				delete[] _renderData;
+			if (_renderData2)
+				delete[] _renderData2;
+
 			_objects = new Mult_Object[_objCount];
+			memset(_objects, 0, _objCount * sizeof(Mult_Object));
 
 			_orderArray = new int8[_objCount];
+			memset(_orderArray, 0, _objCount * sizeof(int8));
 			_renderData = new int16[9 * _objCount];
+			memset(_renderData, 0, _objCount * 9 * sizeof(int16));
 			_renderData2 = new Mult_Object*[_objCount];
+			memset(_renderData2, 0, _objCount * sizeof(Mult_Object*));
 
 			_animArrayX = new int32[_objCount];
 			_animArrayY = new int32[_objCount];
@@ -485,7 +514,7 @@
 
 		_frame++;
 		_vm->_util->waitEndFrame();
-	} while (stop == 0 && stopNoClear == 0);
+	} while (stop == 0 && stopNoClear == 0 && !_vm->_quitRequested);
 
 	if (stopNoClear == 0) {
 		if (_animDataAllocated) {
@@ -504,6 +533,9 @@
 			delete[] _animArrayData;
 			_animArrayData = 0;
 
+			delete[] _orderArray;
+			_orderArray = 0;
+
 			if (_vm->_anim->_animSurf)
 				_vm->_video->freeSurfDesc(_vm->_anim->_animSurf);
 			_vm->_anim->_animSurf = 0;
@@ -1348,6 +1380,10 @@
 		_animDataAllocated = 0;
 	}
 
+	for (i = 0; i < 8; i++)
+		if (_multDatas[i] == _multData2)
+			_multDatas[i] = 0;
+
 	delete _multData2;
 	_multData2 = 0;
 }

Modified: scummvm/trunk/engines/gob/music.cpp
===================================================================
--- scummvm/trunk/engines/gob/music.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/music.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -72,6 +72,8 @@
 };
 
 Music::Music(GobEngine *vm) : _vm(vm) {
+	int i;
+
 	_data = 0;
 	_playPos = 0;
 	_dataSize = 0;
@@ -81,15 +83,20 @@
 	_first = true;
 	_ended = false;
 	_playing = false;
+	_needFree = false;
 	_repCount = -1;
 	_samplesTillPoll = 0;
 
+	for (i = 0; i < 16; i ++)
+		_pollNotes[i] = 0;
+
 	setFreqs();
 }
 
 Music::~Music(void) {
-	if (_data);
-		delete _data;
+	OPLDestroy(_opl);
+	if (_data && _needFree)
+		delete[] _data;
 	_vm->_mixer->setupPremix(0);
 }
 
@@ -439,6 +446,7 @@
 	if (!song.isOpen())
 		return false;
 
+	_needFree = true;
 	_dataSize = song.size();
 	_data = new byte[_dataSize];
 	song.read(_data, _dataSize);
@@ -452,7 +460,7 @@
 }
 
 void Music::loadFromMemory(byte *data) {
-	_playing = false;
+	unloadMusic();
 	_repCount = 0;
 
 	_dataSize = (uint32) -1;
@@ -466,8 +474,10 @@
 void Music::unloadMusic(void) {
 	_playing = false;
 
-	if (_data)
-		delete _data;
+	if (_data && _needFree)
+		delete[] _data;
+
+	_needFree = false;
 }
 
 } // End of namespace Gob

Modified: scummvm/trunk/engines/gob/music.h
===================================================================
--- scummvm/trunk/engines/gob/music.h	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/music.h	2006-05-31 08:44:14 UTC (rev 22790)
@@ -83,6 +83,7 @@
 	bool _playing;
 	bool _first;
 	bool _ended;
+	bool _needFree;
 	Common::Mutex _mutex;
 	GobEngine *_vm;
 

Modified: scummvm/trunk/engines/gob/util.cpp
===================================================================
--- scummvm/trunk/engines/gob/util.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/util.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -26,6 +26,7 @@
 #include "gob/util.h"
 #include "gob/draw.h"
 #include "gob/game.h"
+#include "gob/inter.h"
 
 namespace Gob {
 
@@ -162,7 +163,7 @@
 		case OSystem::EVENT_KEYUP:
 			break;
 		case OSystem::EVENT_QUIT:
-			g_system->quit();
+			_vm->_quitRequested = true;
 			break;
 		default:
 			break;

Modified: scummvm/trunk/engines/gob/video.cpp
===================================================================
--- scummvm/trunk/engines/gob/video.cpp	2006-05-31 08:32:24 UTC (rev 22789)
+++ scummvm/trunk/engines/gob/video.cpp	2006-05-31 08:44:14 UTC (rev 22790)
@@ -37,9 +37,13 @@
 
 Video::Video(GobEngine *vm) : _vm(vm) {
 	_extraMode = false;
+	_videoDriver = 0;
 }
 
 char Video::initDriver(int16 vidMode) {
+	if (_videoDriver)
+		return 1;
+
 	warning("STUB: Video::initDriver");
 
 	// FIXME: Finish all this stuff :)
@@ -81,6 +85,9 @@
 }
 
 void Video::freeSurfDesc(SurfaceDesc * surfDesc) {
+	if (surfDesc == 0)
+		return;
+
 	delete[] surfDesc->vidPtr;
 	// GOB2: surfDesc != _vm->_draw->_frontSurface (since _frontSurface is set
 	// to _pPrimarySurfDesc in Game::prepareStart(), is there a difference?)


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