[Scummvm-git-logs] scummvm master -> 2e2bb61499a8be5587963a3bda246c5ca817f9d7

kelmer44 noreply at scummvm.org
Thu Sep 18 08:21:41 UTC 2025


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
2e2bb61499 TOT: Fixes leaks on room loading and talking


Commit: 2e2bb61499a8be5587963a3bda246c5ca817f9d7
    https://github.com/scummvm/scummvm/commit/2e2bb61499a8be5587963a3bda246c5ca817f9d7
Author: kelmer (kelmer at gmail.com)
Date: 2025-09-18T10:21:11+02:00

Commit Message:
TOT: Fixes leaks on room loading and talking

Changed paths:
    engines/tot/dialog.cpp
    engines/tot/engine.cpp
    engines/tot/graphics.cpp
    engines/tot/graphics.h
    engines/tot/tot.cpp
    engines/tot/types.h
    engines/tot/util.cpp
    engines/tot/util.h


diff --git a/engines/tot/dialog.cpp b/engines/tot/dialog.cpp
index 54eaf05b80c..55247c1746c 100644
--- a/engines/tot/dialog.cpp
+++ b/engines/tot/dialog.cpp
@@ -577,6 +577,7 @@ void loadTalkAnimations() {
 	animFile.seek(offset);
 	// Will load talking anim always in the upwards direction of the walk cycle array
 	for (int i = 0; i < 16; i++) {
+		free(g_engine->_mainCharAnimation.bitmap[0][i]);
 		g_engine->_mainCharAnimation.bitmap[0][i] = (byte *)malloc(g_engine->_mainCharFrameSize);
 		animFile.read(g_engine->_mainCharAnimation.bitmap[0][i], g_engine->_mainCharFrameSize);
 	}
@@ -584,7 +585,6 @@ void loadTalkAnimations() {
 
 	if ((g_engine->_currentRoomData->animationName != "PETER") && (g_engine->_currentRoomData->animationName != "ARZCAEL")) {
 		g_engine->_iframe2 = 0;
-		free(g_engine->_curSecondaryAnimationFrame);
 		bool result;
 		switch (g_engine->_curObject.speaking) {
 		case 1:
@@ -603,10 +603,10 @@ void loadTalkAnimations() {
 		g_engine->_secondaryAnimationFrameCount = animFile.readByte();
 		g_engine->_secondaryAnimDirCount = animFile.readByte();
 
-		g_engine->_curSecondaryAnimationFrame = (byte *)malloc(g_engine->_secondaryAnimFrameSize);
+		newSecondaryAnimationFrame();
 		if (g_engine->_secondaryAnimDirCount != 0) {
 			g_engine->_secondaryAnimationFrameCount = g_engine->_secondaryAnimationFrameCount / 4;
-			for (int i = 0; i <= 3; i++) {
+			for (int i = 0; i < 4; i++) {
 				g_engine->loadAnimationForDirection(&animFile, i);
 			}
 		} else {
@@ -625,6 +625,7 @@ void unloadTalkAnimations() {
 	g_engine->_mainCharFrameSize = animFile.readUint16LE();
 
 	for (int i = 0; i < kWalkFrameCount; i++) {
+		free(g_engine->_mainCharAnimation.bitmap[0][i]);
 		g_engine->_mainCharAnimation.bitmap[0][i] = (byte *)malloc(g_engine->_mainCharFrameSize);
 		animFile.read(g_engine->_mainCharAnimation.bitmap[0][i], g_engine->_mainCharFrameSize);
 	}
@@ -637,7 +638,7 @@ void unloadTalkAnimations() {
 		g_engine->_secondaryAnimFrameSize = animFile.readUint16LE();
 		g_engine->_secondaryAnimationFrameCount = animFile.readByte();
 		g_engine->_secondaryAnimDirCount = animFile.readByte();
-		g_engine->_curSecondaryAnimationFrame = (byte *)malloc(g_engine->_secondaryAnimFrameSize);
+		newSecondaryAnimationFrame();
 		if (g_engine->_secondaryAnimDirCount != 0) {
 
 			g_engine->_secondaryAnimationFrameCount = g_engine->_secondaryAnimationFrameCount / 4;
diff --git a/engines/tot/engine.cpp b/engines/tot/engine.cpp
index 1dcea3d013b..7b85a105dc0 100644
--- a/engines/tot/engine.cpp
+++ b/engines/tot/engine.cpp
@@ -296,10 +296,7 @@ void TotEngine::sprites(bool drawMainCharachter) {
 			if (_isPeterCoughing && !_sound->isVocPlaying()) {
 				_iframe2 = 0;
 			}
-			if(_curSecondaryAnimationFrame != nullptr) {
-				free(_curSecondaryAnimationFrame);
-			}
-			_curSecondaryAnimationFrame = (byte *)malloc(_secondaryAnimFrameSize);
+			newSecondaryAnimationFrame();
 			Common::copy(_secondaryAnimation.bitmap[_secondaryAnimation.dir][_iframe2], _secondaryAnimation.bitmap[_secondaryAnimation.dir][_iframe2] + _secondaryAnimFrameSize,  _curSecondaryAnimationFrame);
 		}
 		uint16 curCharFrameW = READ_LE_UINT16(_curCharacterAnimationFrame);
@@ -706,6 +703,9 @@ void TotEngine::loadScreenData(uint screenNumber) {
 	_currentRoomNumber = screenNumber;
 
 	_rooms->seek(screenNumber * kRoomRegSize, SEEK_SET);
+	if (_currentRoomData) {
+		delete _currentRoomData;
+	}
 	_currentRoomData = readScreenDataFile(_rooms);
 	loadScreen();
 	for (int i = 0; i < 15; i++) {
@@ -3778,6 +3778,9 @@ void TotEngine::loadScrollData(uint roomCode, bool rightScroll, uint horizontalP
 	// Start screen 2
 
 	_rooms->seek(roomCode * kRoomRegSize, SEEK_SET);
+	if (_currentRoomData) {
+		delete _currentRoomData;
+	}
 	_currentRoomData = readScreenDataFile(_rooms);
 
 	loadScreen();
@@ -4069,8 +4072,14 @@ void TotEngine::initScreenPointers() {
 }
 
 void TotEngine::loadAnimationForDirection(Common::SeekableReadStream *stream, int direction) {
+	uint size = _secondaryAnimFrameSize;
 	for (int j = 0; j < _secondaryAnimationFrameCount; j++) {
-		_graphics->loadAnimationIntoBuffer(stream, _secondaryAnimation.bitmap[direction][j], _secondaryAnimFrameSize);
+		if (_secondaryAnimation.bitmap[direction][j]) {
+			free(_secondaryAnimation.bitmap[direction][j]);
+		}
+		_secondaryAnimation.bitmap[direction][j] = (byte *)malloc(size);
+		stream->read(_secondaryAnimation.bitmap[direction][j], size);
+		Common::copy(_secondaryAnimation.bitmap[direction][j], _secondaryAnimation.bitmap[direction][j] + size, g_engine->_curSecondaryAnimationFrame);
 	}
 }
 
@@ -4090,11 +4099,11 @@ void TotEngine::loadAnimation(const Common::String &animationName) {
 	_secondaryAnimFrameSize = animFile.readUint16LE();
 	_secondaryAnimationFrameCount = animFile.readByte();
 	_secondaryAnimDirCount = animFile.readByte();
-	_curSecondaryAnimationFrame = (byte *)malloc(_secondaryAnimFrameSize);
+	newSecondaryAnimationFrame();
 	if (_secondaryAnimDirCount != 0) {
 
 		_secondaryAnimationFrameCount = _secondaryAnimationFrameCount / 4;
-		for (int i = 0; i <= 3; i++) {
+		for (int i = 0; i < 4; i++) {
 			loadAnimationForDirection(&animFile, i);
 		}
 	} else {
@@ -4144,6 +4153,9 @@ void TotEngine::updateAltScreen(byte otherScreenNumber) {
 
 	// Load other screen
 	_rooms->seek(otherScreenNumber * kRoomRegSize, SEEK_SET);
+	if (_currentRoomData) {
+		delete _currentRoomData;
+	}
 	_currentRoomData = readScreenDataFile(_rooms);
 
 	switch (otherScreenNumber) {
@@ -4220,6 +4232,9 @@ void TotEngine::updateAltScreen(byte otherScreenNumber) {
 
 	// Restore current room again
 	_rooms->seek(currentScreen * kRoomRegSize, SEEK_SET);
+	if (_currentRoomData) {
+		delete _currentRoomData;
+	}
 	_currentRoomData = readScreenDataFile(_rooms);
 
 	setRoomTrajectories(_secondaryAnimHeight, _secondaryAnimWidth, SET_WITH_ANIM);
@@ -4296,10 +4311,13 @@ void TotEngine::clearScreenLayers() {
 void TotEngine::clearAnimation() {
 	if (_isSecondaryAnimationEnabled) {
 		_isSecondaryAnimationEnabled = false;
+		if (_curSecondaryAnimationFrame != nullptr) {
+			free(_curSecondaryAnimationFrame);
+		}
 		_curSecondaryAnimationFrame = nullptr;
-		for(int j = 0; j < _secondaryAnimDirCount; j++){
-			for(int i = 0; i < _secondaryAnimationFrameCount; i++){
-				if(_secondaryAnimation.bitmap[j][i] != nullptr && _secondaryAnimation.bitmap[j][i] != _curSecondaryAnimationFrame) {
+		for (int j = 0; j < _secondaryAnimDirCount; j++) {
+			for (int i = 0; i < _secondaryAnimationFrameCount; i++) {
+				if (_secondaryAnimation.bitmap[j][i] != nullptr && _secondaryAnimation.bitmap[j][i] != _curSecondaryAnimationFrame) {
 					free(_secondaryAnimation.bitmap[j][i]);
 				}
 				_secondaryAnimation.bitmap[j][i] = nullptr;
@@ -5397,7 +5415,7 @@ void TotEngine::loadBat() {
 	_secondaryAnimFrameSize = animFile.readUint16LE();
 	_secondaryAnimationFrameCount = animFile.readByte();
 	_secondaryAnimDirCount = animFile.readByte();
-	_curSecondaryAnimationFrame = (byte *)malloc(_secondaryAnimFrameSize);
+	newSecondaryAnimationFrame();
 	loadAnimationForDirection(&animFile, 0);
 	animFile.close();
 }
@@ -5412,7 +5430,7 @@ void TotEngine::loadDevil() {
 	_secondaryAnimFrameSize = animFile.readUint16LE();
 	_secondaryAnimationFrameCount = animFile.readByte();
 	_secondaryAnimDirCount = animFile.readByte();
-	_curSecondaryAnimationFrame = (byte *)malloc(_secondaryAnimFrameSize);
+	newSecondaryAnimationFrame();
 	if (_secondaryAnimDirCount != 0) {
 		_secondaryAnimationFrameCount = _secondaryAnimationFrameCount / 4;
 		for (int i = 0; i <= 3; i++) {
diff --git a/engines/tot/graphics.cpp b/engines/tot/graphics.cpp
index 674ce28d5d3..ba5db3f117d 100644
--- a/engines/tot/graphics.cpp
+++ b/engines/tot/graphics.cpp
@@ -1041,10 +1041,4 @@ void GraphicsManager::restoreBackground() {
 	Common::copy(g_engine->_backgroundCopy + 4, g_engine->_backgroundCopy + g_engine->_screenSize, g_engine->_sceneBackground + 4);
 }
 
-void GraphicsManager::loadAnimationIntoBuffer(Common::SeekableReadStream *stream, byte *&buf, int animSize) {
-	buf = (byte *)malloc(animSize);
-	stream->read(buf, animSize);
-	Common::copy(buf, buf + animSize, g_engine->_curSecondaryAnimationFrame);
-}
-
 } // End of namespace Tot
diff --git a/engines/tot/graphics.h b/engines/tot/graphics.h
index dced943460d..64a931f36ca 100644
--- a/engines/tot/graphics.h
+++ b/engines/tot/graphics.h
@@ -74,7 +74,6 @@ public:
 	void sceneTransition(bool fadeToBlack, byte *screen);
 
 	void advancePaletteAnim();
-	void loadAnimationIntoBuffer(Common::SeekableReadStream *stream, byte *&buf, int animSize);
 	void printColor(int x, int y, int color);
 	void updateSceneArea(int speed = 1);
 
diff --git a/engines/tot/tot.cpp b/engines/tot/tot.cpp
index b370d747ed9..1fe85621fc0 100644
--- a/engines/tot/tot.cpp
+++ b/engines/tot/tot.cpp
@@ -624,6 +624,10 @@ void TotEngine::changeRoom() {
 	saveRoomData(_currentRoomData, _rooms);
 	_sound->setSfxVolume(_sound->_leftSfxVol, _sound->_rightSfxVol);
 
+	if (_currentRoomData->doors[_doorIndex].nextScene != 255) {
+		clearAnimation();
+		clearScreenLayers();
+	}
 	switch (_currentRoomData->doors[_doorIndex].nextScene) {
 	case 2: {
 		_iframe = 0;
@@ -632,8 +636,6 @@ void TotEngine::changeRoom() {
 		_characterPosY = _currentRoomData->doors[_doorIndex].exitPosY - kCharacerCorrectionY;
 		_trajectory[_currentTrajectoryIndex].x = _characterPosX;
 		_trajectory[_currentTrajectoryIndex].y = _characterPosY;
-		clearAnimation();
-		clearScreenLayers();
 		_mouse->hide();
 
 		_graphics->sceneTransition(true, nullptr);
@@ -649,8 +651,6 @@ void TotEngine::changeRoom() {
 		_graphics->sceneTransition(false, _sceneBackground);
 		_cpCounter = _cpCounter2;
 		_mouse->show();
-		_oldGridX = 0;
-		_oldGridY = 0;
 	} break;
 	case 5: {
 		if (_currentRoomData->code != 6) {
@@ -660,8 +660,6 @@ void TotEngine::changeRoom() {
 			_characterPosY = _currentRoomData->doors[_doorIndex].exitPosY - kCharacerCorrectionY + 15;
 			_trajectory[_currentTrajectoryIndex].x = _characterPosX;
 			_trajectory[_currentTrajectoryIndex].y = _characterPosY;
-			clearAnimation();
-			clearScreenLayers();
 			_mouse->hide();
 			_graphics->sceneTransition(true, nullptr);
 			loadScreenData(_currentRoomData->doors[_doorIndex].nextScene);
@@ -670,42 +668,26 @@ void TotEngine::changeRoom() {
 			_sound->setSfxVolume(_sound->_leftSfxVol, 0);
 			_graphics->sceneTransition(false, _sceneBackground);
 			_mouse->show();
-			_oldGridX = 0;
-			_oldGridY = 0;
-			checkMouseGrid();
 		} else {
-
 			_currentZone = _currentRoomData->walkAreasGrid[(_characterPosX + kCharacterCorrectionX) / kXGridCount][(_characterPosY + kCharacerCorrectionY) / kYGridCount];
 			_targetZone = 21;
 			goToObject(_currentZone, _targetZone);
-			clearAnimation();
-			clearScreenLayers();
 			_mouse->hide();
 			_sound->setSfxVolume(_sound->_leftSfxVol, 0);
 			loadScrollData(_currentRoomData->doors[_doorIndex].nextScene, true, 22, -2);
 			_mouse->show();
-			_oldGridX = 0;
-			_oldGridY = 0;
-			checkMouseGrid();
 		}
 	} break;
 	case 6: {
 		_currentZone = _currentRoomData->walkAreasGrid[(_characterPosX + kCharacterCorrectionX) / kXGridCount][(_characterPosY + kCharacerCorrectionY) / kYGridCount];
 		_targetZone = 27;
 		goToObject(_currentZone, _targetZone);
-		clearAnimation();
-		clearScreenLayers();
 		_mouse->hide();
 		_sound->setSfxVolume(_sound->_leftSfxVol, _sound->_rightSfxVol);
 		loadScrollData(_currentRoomData->doors[_doorIndex].nextScene, false, 22, 2);
 		_mouse->show();
-		_oldGridX = 0;
-		_oldGridY = 0;
-		checkMouseGrid();
 	} break;
 	case 9: {
-		clearAnimation();
-		clearScreenLayers();
 		_mouse->hide();
 		_graphics->sceneTransition(true, nullptr);
 		_iframe = 0;
@@ -718,9 +700,6 @@ void TotEngine::changeRoom() {
 		_graphics->sceneTransition(false, _sceneBackground);
 		_mouse->show();
 		if (getRandom(2) == 0) copyProtection();
-		_oldGridX = 0;
-		_oldGridY = 0;
-		checkMouseGrid();
 	} break;
 	case 12: {
 		if (_currentRoomData->code != 13) {
@@ -730,28 +709,17 @@ void TotEngine::changeRoom() {
 			_characterPosY = _currentRoomData->doors[_doorIndex].exitPosY - kCharacerCorrectionY;
 			_trajectory[_currentTrajectoryIndex].x = _characterPosX;
 			_trajectory[_currentTrajectoryIndex].y = _characterPosY;
-			clearAnimation();
-			clearScreenLayers();
 			_mouse->hide();
 			_graphics->sceneTransition(true, nullptr);
 			loadScreenData(_currentRoomData->doors[_doorIndex].nextScene);
 			_graphics->sceneTransition(false, _sceneBackground);
 			_mouse->show();
-			_oldGridX = 0;
-			_oldGridY = 0;
-			_mouse->show();
 		} else {
-
 			_currentZone = _currentRoomData->walkAreasGrid[(_characterPosX + kCharacterCorrectionX) / kXGridCount][(_characterPosY + kCharacerCorrectionY) / kYGridCount];
 			goToObject(_currentZone, _targetZone);
-			clearAnimation();
-			clearScreenLayers();
 			_mouse->hide();
 			loadScrollData(_currentRoomData->doors[_doorIndex].nextScene, false, 64, 0);
 			_mouse->show();
-			_oldGridX = 0;
-			_oldGridY = 0;
-			checkMouseGrid();
 		}
 	} break;
 	case 13: {
@@ -759,26 +727,16 @@ void TotEngine::changeRoom() {
 		case 12: {
 			_currentZone = _currentRoomData->walkAreasGrid[(_characterPosX + kCharacterCorrectionX) / kXGridCount][(_characterPosY + kCharacerCorrectionY) / kYGridCount];
 			goToObject(_currentZone, _targetZone);
-			clearAnimation();
-			clearScreenLayers();
 			_mouse->hide();
 			loadScrollData(_currentRoomData->doors[_doorIndex].nextScene, true, 64, 0);
 			_mouse->show();
-			_oldGridX = 0;
-			_oldGridY = 0;
-			checkMouseGrid();
 		} break;
 		case 14: {
 			_currentZone = _currentRoomData->walkAreasGrid[(_characterPosX + kCharacterCorrectionX) / kXGridCount][(_characterPosY + kCharacerCorrectionY) / kYGridCount];
 			goToObject(_currentZone, _targetZone);
-			clearAnimation();
-			clearScreenLayers();
 			_mouse->hide();
 			loadScrollData(_currentRoomData->doors[_doorIndex].nextScene, false, 56, 0);
 			_mouse->show();
-			_oldGridX = 0;
-			_oldGridY = 0;
-			checkMouseGrid();
 		} break;
 		}
 	} break;
@@ -790,28 +748,17 @@ void TotEngine::changeRoom() {
 			_characterPosY = _currentRoomData->doors[_doorIndex].exitPosY - kCharacerCorrectionY;
 			_trajectory[_currentTrajectoryIndex].x = _characterPosX;
 			_trajectory[_currentTrajectoryIndex].y = _characterPosY;
-			clearAnimation();
-			clearScreenLayers();
 			_mouse->hide();
 			_graphics->sceneTransition(true, nullptr);
 			loadScreenData(_currentRoomData->doors[_doorIndex].nextScene);
 			_graphics->sceneTransition(false, _sceneBackground);
 			_mouse->show();
-			_oldGridX = 0;
-			_oldGridY = 0;
-			checkMouseGrid();
 		} else {
-
 			_currentZone = _currentRoomData->walkAreasGrid[((_characterPosX + kCharacterCorrectionX) / kXGridCount)][((_characterPosY + kCharacerCorrectionY) / kYGridCount)];
 			goToObject(_currentZone, _targetZone);
-			clearAnimation();
-			clearScreenLayers();
 			_mouse->hide();
 			loadScrollData(_currentRoomData->doors[_doorIndex].nextScene, true, 56, 0);
 			_mouse->show();
-			_oldGridX = 0;
-			_oldGridY = 0;
-			checkMouseGrid();
 		}
 	} break;
 	case 17: {
@@ -821,8 +768,6 @@ void TotEngine::changeRoom() {
 		_characterPosY = _currentRoomData->doors[_doorIndex].exitPosY - kCharacerCorrectionY;
 		_trajectory[_currentTrajectoryIndex].x = _characterPosX;
 		_trajectory[_currentTrajectoryIndex].y = _characterPosY;
-		clearAnimation();
-		clearScreenLayers();
 		_mouse->hide();
 		_graphics->sceneTransition(true, nullptr);
 		_sound->stopVoc();
@@ -835,9 +780,6 @@ void TotEngine::changeRoom() {
 		_graphics->sceneTransition(false, _sceneBackground);
 		_cpCounter = _cpCounter2;
 		_mouse->show();
-		_oldGridX = 0;
-		_oldGridY = 0;
-		checkMouseGrid();
 	} break;
 	case 18: {
 		if (_currentRoomData->code != 19) {
@@ -847,28 +789,18 @@ void TotEngine::changeRoom() {
 			_characterPosY = _currentRoomData->doors[_doorIndex].exitPosY - kCharacerCorrectionY;
 			_trajectory[_currentTrajectoryIndex].x = _characterPosX;
 			_trajectory[_currentTrajectoryIndex].y = _characterPosY;
-			clearAnimation();
-			clearScreenLayers();
 			_mouse->hide();
 			_graphics->sceneTransition(true, nullptr);
 			loadScreenData(_currentRoomData->doors[_doorIndex].nextScene);
 			_graphics->sceneTransition(false, _sceneBackground);
 			_mouse->show();
-			_oldGridX = 0;
-			_oldGridY = 0;
-			checkMouseGrid();
 		} else {
 
 			_currentZone = _currentRoomData->walkAreasGrid[((_characterPosX + kCharacterCorrectionX) / kXGridCount)][((_characterPosY + kCharacerCorrectionY) / kYGridCount)];
 			goToObject(_currentZone, _targetZone);
-			clearAnimation();
-			clearScreenLayers();
 			_mouse->hide();
 			loadScrollData(_currentRoomData->doors[_doorIndex].nextScene, true, 131, -1);
 			_mouse->show();
-			_oldGridX = 0;
-			_oldGridY = 0;
-			checkMouseGrid();
 		}
 	} break;
 	case 19: {
@@ -879,28 +811,17 @@ void TotEngine::changeRoom() {
 			_characterPosY = _currentRoomData->doors[_doorIndex].exitPosY - kCharacerCorrectionY;
 			_trajectory[_currentTrajectoryIndex].x = _characterPosX;
 			_trajectory[_currentTrajectoryIndex].y = _characterPosY;
-			clearAnimation();
-			clearScreenLayers();
 			_mouse->hide();
 			_graphics->sceneTransition(true, nullptr);
 			loadScreenData(_currentRoomData->doors[_doorIndex].nextScene);
 			_graphics->sceneTransition(false, _sceneBackground);
 			_mouse->show();
-			_oldGridX = 0;
-			_oldGridY = 0;
-			checkMouseGrid();
 		} else {
-
 			_currentZone = _currentRoomData->walkAreasGrid[((_characterPosX + kCharacterCorrectionX) / kXGridCount)][((_characterPosY + kCharacerCorrectionY) / kYGridCount)];
 			goToObject(_currentZone, _targetZone);
-			clearAnimation();
-			clearScreenLayers();
 			_mouse->hide();
 			loadScrollData(_currentRoomData->doors[_doorIndex].nextScene, false, 131, 1);
 			_mouse->show();
-			_oldGridX = 0;
-			_oldGridY = 0;
-			checkMouseGrid();
 		}
 	} break;
 	case 20: {
@@ -910,8 +831,6 @@ void TotEngine::changeRoom() {
 		_characterPosY = _currentRoomData->doors[_doorIndex].exitPosY - kCharacerCorrectionY;
 		_trajectory[_currentTrajectoryIndex].x = _characterPosX;
 		_trajectory[_currentTrajectoryIndex].y = _characterPosY;
-		clearAnimation();
-		clearScreenLayers();
 		_mouse->hide();
 		_graphics->sceneTransition(true, nullptr);
 		_sound->stopVoc();
@@ -938,9 +857,6 @@ void TotEngine::changeRoom() {
 		_graphics->sceneTransition(false, _sceneBackground);
 		_cpCounter = _cpCounter2;
 		_mouse->show();
-		_oldGridX = 0;
-		_oldGridY = 0;
-		checkMouseGrid();
 	} break;
 	case 24: {
 		_iframe = 0;
@@ -949,8 +865,6 @@ void TotEngine::changeRoom() {
 		_characterPosY = _currentRoomData->doors[_doorIndex].exitPosY - kCharacerCorrectionY;
 		_trajectory[_currentTrajectoryIndex].x = _characterPosX;
 		_trajectory[_currentTrajectoryIndex].y = _characterPosY;
-		clearAnimation();
-		clearScreenLayers();
 		_mouse->hide();
 		_graphics->sceneTransition(true, nullptr);
 		_sound->stopVoc();
@@ -1002,9 +916,6 @@ void TotEngine::changeRoom() {
 			runaroundRed();
 		_cpCounter = _cpCounter2;
 		_mouse->show();
-		_oldGridX = 0;
-		_oldGridY = 0;
-		checkMouseGrid();
 	} break;
 	case 255:
 		wcScene();
@@ -1016,8 +927,7 @@ void TotEngine::changeRoom() {
 		_characterPosY = _currentRoomData->doors[_doorIndex].exitPosY - kCharacerCorrectionY;
 		_trajectory[_currentTrajectoryIndex].x = _characterPosX;
 		_trajectory[_currentTrajectoryIndex].y = _characterPosY;
-		clearAnimation();
-		clearScreenLayers();
+
 		_mouse->hide();
 		_graphics->sceneTransition(true, nullptr);
 		_sound->stopVoc();
@@ -1036,11 +946,14 @@ void TotEngine::changeRoom() {
 		_graphics->sceneTransition(false, _sceneBackground);
 		_cpCounter = _cpCounter2;
 		_mouse->show();
+	}
+	}
+	
+	if (_currentRoomData->doors[_doorIndex].nextScene != 255) {
 		_oldGridX = 0;
 		_oldGridY = 0;
 		checkMouseGrid();
 	}
-	}
 	_oldTargetZone = 0;
 }
 
@@ -1270,11 +1183,13 @@ void TotEngine::clearVars() {
 	if (_sceneObjectsData != nullptr) {
 		delete _sceneObjectsData;
 	}
-	for (int i = 0; i < kNumScreenOverlays; i++) {
-		if (_screenLayers[i] != nullptr) {
-			free(_screenLayers[i]);
-		}
+
+	if (_currentRoomData) {
+		delete _currentRoomData;
 	}
+	
+	clearScreenLayers();
+
 	for (int i = 0; i < kInventoryIconCount; i++) {
 		if (_inventoryIconBitmaps[i] != nullptr) {
 			free(_inventoryIconBitmaps[i]);
diff --git a/engines/tot/types.h b/engines/tot/types.h
index 03bcee8f3ac..9dec3752c03 100644
--- a/engines/tot/types.h
+++ b/engines/tot/types.h
@@ -207,6 +207,12 @@ struct RoomFileRegister {
 	Common::Point secondaryAnimTrajectory[300];					/* trajectory of the secondary animation */
 	uint16 secondaryAnimDirections[300];						/* directions of the secondary trajectory. Pos 300 reflects object code. */
 	uint16 secondaryTrajectoryLength;							/* length of the trajectory of the secondary animation */
+	~RoomFileRegister() {
+		for (int i = 0; i < 51; i++) {
+			delete screenObjectIndex[i];
+			screenObjectIndex[i] = nullptr;
+		}
+	}
 };
 
 struct SavedGame {
diff --git a/engines/tot/util.cpp b/engines/tot/util.cpp
index b5263ea3e74..0b7b249ccf1 100644
--- a/engines/tot/util.cpp
+++ b/engines/tot/util.cpp
@@ -24,6 +24,7 @@
 #include "tot/statics.h"
 #include "tot/tot.h"
 #include "tot/util.h"
+#include "util.h"
 
 namespace Tot {
 
@@ -526,5 +527,10 @@ const int32 *getOffsetsByCurrentLanguage() {
 	return (g_engine->_lang == Common::ES_ESP) ? flcOffsets[0] : flcOffsets[1];
 }
 
-
+void newSecondaryAnimationFrame() {
+	if (g_engine->_curSecondaryAnimationFrame != nullptr) {
+		free(g_engine->_curSecondaryAnimationFrame);
+	}
+	g_engine->_curSecondaryAnimationFrame = (byte *)malloc(g_engine->_secondaryAnimFrameSize);
+}
 } // End of namespace Tot
diff --git a/engines/tot/util.h b/engines/tot/util.h
index 78092cf5e70..3b06a3c137e 100644
--- a/engines/tot/util.h
+++ b/engines/tot/util.h
@@ -80,6 +80,8 @@ const char *const *getHardcodedTextsByCurrentLanguage();
 
 const int32 *getOffsetsByCurrentLanguage();
 
+void newSecondaryAnimationFrame();
+
 inline bool isLanguageSpanish() {
 	return g_engine->_lang == Common::ES_ESP;
 };




More information about the Scummvm-git-logs mailing list