[Scummvm-git-logs] scummvm master -> ff3682aae1152839dd5afd2bd69492ec7d6fc460

Strangerke noreply at scummvm.org
Tue Feb 6 23:09:21 UTC 2024


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

Summary:
ff3682aae1 EFH: Fix various crashes when exiting in the middle of an interaction


Commit: ff3682aae1152839dd5afd2bd69492ec7d6fc460
    https://github.com/scummvm/scummvm/commit/ff3682aae1152839dd5afd2bd69492ec7d6fc460
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-02-07T00:09:15+01:00

Commit Message:
EFH: Fix various crashes when exiting in the middle of an interaction

Changed paths:
    engines/efh/efh.cpp
    engines/efh/efh.h
    engines/efh/fight.cpp
    engines/efh/files.cpp
    engines/efh/menu.cpp
    engines/efh/script.cpp
    engines/efh/sound.cpp
    engines/efh/utils.cpp


diff --git a/engines/efh/efh.cpp b/engines/efh/efh.cpp
index 5aa48025e2f..506d7d63e6c 100644
--- a/engines/efh/efh.cpp
+++ b/engines/efh/efh.cpp
@@ -84,7 +84,7 @@ Common::Error EfhEngine::run() {
 		return Common::kNoError;
 
 	uint32 lastMs = _system->getMillis();
-	while (!_shouldQuit) {
+	while (!shouldQuitGame()) {
 		_system->delayMillis(20);
 		uint32 newMs = _system->getMillis();
 
@@ -241,7 +241,7 @@ Common::Error EfhEngine::run() {
 			break;
 		}
 
-		if ((_mapPosX != _oldMapPosX || _mapPosY != _oldMapPosY) && !_shouldQuit) {
+		if ((_mapPosX != _oldMapPosX || _mapPosY != _oldMapPosY) && !shouldQuitGame()) {
 			bool collisionFl = checkMonsterCollision();
 			if (collisionFl) {
 				_oldMapPosX = _mapPosX;
@@ -262,16 +262,16 @@ Common::Error EfhEngine::run() {
 			}
 		}
 
-		if (!_shouldQuit) {
+		if (!shouldQuitGame()) {
 			handleMapMonsterMoves();
 		}
 
-		if (_redrawNeededFl && !_shouldQuit) {
+		if (_redrawNeededFl && !shouldQuitGame()) {
 			drawScreen();
 			displayLowStatusScreen(true);
 		}
 
-		if (!_shouldQuit) {
+		if (!shouldQuitGame()) {
 			handleNewRoundEffects();
 
 			if (_tempTextDelay > 0) {
@@ -871,7 +871,7 @@ void EfhEngine::handleWinSequence() {
 
 	Common::KeyCode input = Common::KEYCODE_INVALID;
 
-	while (input != Common::KEYCODE_ESCAPE) {
+	while (input != Common::KEYCODE_ESCAPE && !shouldQuitGame()) {
 		displayRawDataAtPos(winSeqSubFilesArray1[0], 0, 0);
 		displayFctFullScreen();
 		displayRawDataAtPos(winSeqSubFilesArray1[0], 0, 0);
@@ -1721,7 +1721,7 @@ void EfhEngine::handleMapMonsterMoves() {
 
 				break;
 			}
-		} while (!monsterMovedFl && retryCounter > 0);
+		} while (!monsterMovedFl && retryCounter > 0 && !shouldQuitGame());
 	}
 
 	if (attackMonsterId != -1)
@@ -2058,7 +2058,7 @@ void EfhEngine::displayImp1Text(int16 textId) {
 						curTextId = nextTextId;
 				}
 
-			} while (!textComplete && curTextId != -1);
+			} while (!textComplete && curTextId != -1 && !shouldQuitGame());
 
 			textComplete = false;
 			if (curTextId == 0xFF || curTextId == -1)
@@ -2445,7 +2445,7 @@ bool EfhEngine::checkMonsterCollision() {
 			default:
 				break;
 			}
-		} while (!endLoop);
+		} while (!endLoop && !shouldQuitGame());
 		return false;
 	}
 
diff --git a/engines/efh/efh.h b/engines/efh/efh.h
index f83a1a5b769..9496fc69307 100644
--- a/engines/efh/efh.h
+++ b/engines/efh/efh.h
@@ -283,6 +283,7 @@ public:
 	Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
 
 	bool _shouldQuit;
+	bool shouldQuitGame() const { return _shouldQuit || shouldQuit(); }
 
 protected:
 	int _lastTime;
diff --git a/engines/efh/fight.cpp b/engines/efh/fight.cpp
index dc1c4c4cffb..95f4650a395 100644
--- a/engines/efh/fight.cpp
+++ b/engines/efh/fight.cpp
@@ -94,7 +94,7 @@ bool EfhEngine::handleFight(int16 monsterId) {
 
 	drawCombatScreen(0, false, true);
 
-	for (bool mainLoopCond = false; !mainLoopCond;) {
+	for (bool mainLoopCond = false; !mainLoopCond && !shouldQuitGame();) {
 		if (isTPK()) {
 			resetTeamMonsterIdArray();
 			_ongoingFightFl = false;
@@ -345,7 +345,8 @@ void EfhEngine::handleFight_lastAction_A(int16 teamCharId) {
 						addReactionText(kEfhReactionCriesOut);
 					} else if (_mapMonsters[_techId][_teamMonster[groupId]._id]._hitPoints[ctrMobsterId] < hitPointsBefore / 4) {
 						addReactionText(kEfhReactionFalters);
-					// The original checked /2 before /3, making the code in /3 unreachable. This fix allow the originally text to be displayed
+					// The original checked /2 before /3, making the code in /3 unreachable.
+					// This check has been fixed so that it behaves as originally expected.
 					} else if (_mapMonsters[_techId][_teamMonster[groupId]._id]._hitPoints[ctrMobsterId] < hitPointsBefore / 3) {
 						addReactionText(kEfhReactionScreams);
 					} else if (_mapMonsters[_techId][_teamMonster[groupId]._id]._hitPoints[ctrMobsterId] < hitPointsBefore / 2) {
@@ -353,8 +354,8 @@ void EfhEngine::handleFight_lastAction_A(int16 teamCharId) {
 					} else if (hitPointsBefore / 8 >= originalDamage) {
 						addReactionText(kEfhReactionChortles);
 					} else if (getRandom(100) < 35) {
-						// Note : The original had a bug as it was doing an (always false) check "originalDamage == 0".
-						// This check has been removed so that it behaves as originally expected
+						// Note : The original has a bug as it was doing an (always false) check "originalDamage == 0".
+						// This check has been removed so that it behaves as originally expected.
 						addReactionText(kEfhReactionLaughs);
 					}
 				}
@@ -1021,7 +1022,7 @@ int16 EfhEngine::determineTeamTarget(int16 charId, int16 unkFied18Val, bool chec
 				getLastCharAfterAnimCount(_guessAnimationAmount);
 			}
 		}
-	} while (retVal == -1);
+	} while (retVal == -1 && !shouldQuitGame());
 
 	if (retVal == 27)
 		retVal = -1;
@@ -1127,7 +1128,7 @@ bool EfhEngine::getTeamAttackRoundPlans() {
 			default:
 				break;
 			}
-		} while (_teamChar[charId]._lastAction == 0);
+		} while (_teamChar[charId]._lastAction == 0 && !shouldQuitGame());
 	}
 
 	return retVal;
@@ -1661,7 +1662,7 @@ int16 EfhEngine::selectMonsterGroup() {
 
 	int16 retVal = -1;
 
-	while (retVal == -1) {
+	while (retVal == -1 && !shouldQuitGame()) {
 		Common::KeyCode input = handleAndMapInput(true);
 		switch (input) {
 		case Common::KEYCODE_ESCAPE:
diff --git a/engines/efh/files.cpp b/engines/efh/files.cpp
index b9d593c40fd..cd85c7a5b02 100644
--- a/engines/efh/files.cpp
+++ b/engines/efh/files.cpp
@@ -105,7 +105,7 @@ void EfhEngine::rImageFile(const Common::Path &filename, uint8 *targetBuffer, ui
 	// => Write a class to handle that more properly
 	uint8 *ptr = targetBuffer;
 	uint16 counter = 0;
-	while (READ_LE_INT16(ptr) != 0) {
+	while (READ_LE_INT16(ptr) != 0 && !shouldQuitGame()) {
 		subFilesArray[counter] = ptr;
 		++counter;
 		int16 imageWidth = READ_LE_INT16(ptr);
diff --git a/engines/efh/menu.cpp b/engines/efh/menu.cpp
index 0774c06808a..5fad28053b0 100644
--- a/engines/efh/menu.cpp
+++ b/engines/efh/menu.cpp
@@ -122,7 +122,7 @@ bool EfhEngine::handleDeathMenu() {
 			displayFctFullScreen();
 	}
 
-	for (bool found = false; !found;) {
+	for (bool found = false; !found && !shouldQuitGame();) {
 		Common::KeyCode input = waitForKey();
 		switch (input) {
 		case Common::KEYCODE_l:
@@ -661,7 +661,7 @@ int16 EfhEngine::handleStatusMenu(int16 gameMode, int16 charId) {
 
 			prepareStatusMenu(windowId, menuId, curMenuLine, charId, true);
 
-		} while (!selectionDoneFl); // Loop until a menu entry is confirmed by the user by pressing the enter key
+		} while (!selectionDoneFl && !shouldQuitGame()); // Loop until a menu entry is confirmed by the user by pressing the enter key
 
 		bool validationFl = true;
 
@@ -767,7 +767,7 @@ int16 EfhEngine::handleStatusMenu(int16 gameMode, int16 charId) {
 						}
 						givenFl = false;
 					}
-				} while (!givenFl && !var2 && destCharId != 0x1B);
+				} while (!givenFl && !var2 && destCharId != 0x1B && !shouldQuitGame());
 
 				if (givenFl) {
 					removeObject(charId, objectId);
diff --git a/engines/efh/script.cpp b/engines/efh/script.cpp
index 7486e2854ea..7548600f2aa 100644
--- a/engines/efh/script.cpp
+++ b/engines/efh/script.cpp
@@ -73,7 +73,7 @@ int16 EfhEngine::script_parse(Common::String stringBuffer, int16 posX, int16 pos
 	int16 curWordPos = 0;
 	setTextPos(posX, curLineNb * 9 + posY);
 
-	while (!doneFlag) {
+	while (!doneFlag && !shouldQuitGame()) {
 		uint8 curChar = *buffer;
 		if (curChar != 0x5E && curChar != 0x20 && curChar != 0 && curChar != 0x7C) { // '^', ' ', NUL, '|'
 			noTextFlag = false;
diff --git a/engines/efh/sound.cpp b/engines/efh/sound.cpp
index 309204fb1e1..752b335133e 100644
--- a/engines/efh/sound.cpp
+++ b/engines/efh/sound.cpp
@@ -27,7 +27,7 @@ void EfhEngine::songDelay(int delay) {
 	debugC(3, kDebugEngine, "songDelay %d", delay);
 
 	int remainingDelay = delay / 2;
-	while (remainingDelay > 0 && !shouldQuit()) {
+	while (remainingDelay > 0 && !shouldQuitGame()) {
 		remainingDelay -= 3;
 		_system->delayMillis(3);
 	}
@@ -90,7 +90,7 @@ Common::KeyCode EfhEngine::playSong(uint8 *buffer) {
 			if (inputChar == Common::KEYCODE_ESCAPE || inputChar == Common::KEYCODE_RETURN)
 				stopFl = 0;
 		}
-	} while (stopFl != 0);
+	} while (stopFl != 0 && !shouldQuitGame());
 
 	_mixer->stopHandle(_speakerHandle);
 	delete _speakerStream;
@@ -164,7 +164,7 @@ void EfhEngine::generateSound2(int startFreq, int endFreq, int speed) {
 		songDelay(speed);
 		_speakerStream->stop();
 		curFreq += delta;
-	} while (curFreq < endFreq && !shouldQuit());
+	} while (curFreq < endFreq && !shouldQuitGame());
 
 
 	_mixer->stopHandle(_speakerHandle);
diff --git a/engines/efh/utils.cpp b/engines/efh/utils.cpp
index 87f607d50b7..cb7a71f83a9 100644
--- a/engines/efh/utils.cpp
+++ b/engines/efh/utils.cpp
@@ -59,7 +59,7 @@ void EfhEngine::decryptImpFile(bool techMapFl) {
 				_imp1PtrArray[counter++] = curPtr;
 		} else
 			++curPtr;
-	} while (*curPtr != 0x60 && counter <= target);
+	} while (*curPtr != 0x60 && counter <= target && !shouldQuitGame());
 
 	if (ConfMan.getBool("dump_scripts")) {
 		// Dump the decompressed IMP file
@@ -151,7 +151,7 @@ Common::KeyCode EfhEngine::getLastCharAfterAnimCount(int16 delay) {
 	Common::KeyCode lastChar = Common::KEYCODE_INVALID;
 
 	uint32 lastMs = _system->getMillis();
-	while (delay > 0 && lastChar == Common::KEYCODE_INVALID && !shouldQuit()) {
+	while (delay > 0 && lastChar == Common::KEYCODE_INVALID && !shouldQuitGame()) {
 		_system->delayMillis(20);
 		uint32 newMs = _system->getMillis();
 
@@ -176,7 +176,7 @@ Common::KeyCode EfhEngine::getInput(int16 delay) {
 	Common::KeyCode retVal = Common::KEYCODE_INVALID;
 
 	uint32 lastMs = _system->getMillis();
-	while (delay > 0 && !shouldQuit()) {
+	while (delay > 0 && !shouldQuitGame()) {
 		_system->delayMillis(20);
 		uint32 newMs = _system->getMillis();
 
@@ -227,7 +227,7 @@ Common::KeyCode EfhEngine::waitForKey() {
 	Common::Event event;
 
 	uint32 lastMs = _system->getMillis();
-	while (retVal == Common::KEYCODE_INVALID && !shouldQuit()) {
+	while (retVal == Common::KEYCODE_INVALID && !shouldQuitGame()) {
 		_system->delayMillis(20);
 		uint32 newMs = _system->getMillis();
 
@@ -262,7 +262,7 @@ Common::KeyCode EfhEngine::handleAndMapInput(bool animFl) {
 	Common::KeyCode retVal = Common::KEYCODE_INVALID;
 
 	uint32 lastMs = _system->getMillis();
-	while (retVal == Common::KEYCODE_INVALID && !shouldQuit()) {
+	while (retVal == Common::KEYCODE_INVALID && !shouldQuitGame()) {
 		_system->getEventManager()->pollEvent(event);
 
 		if (event.type == Common::EVENT_KEYUP)
@@ -290,7 +290,7 @@ Common::KeyCode EfhEngine::getInputBlocking() {
 	Common::KeyCode retVal = Common::KEYCODE_INVALID;
 
 	uint32 lastMs = _system->getMillis();
-	while (retVal == Common::KEYCODE_INVALID && !shouldQuit()) {
+	while (retVal == Common::KEYCODE_INVALID && !shouldQuitGame()) {
 		_system->getEventManager()->pollEvent(event);
 
 		if (event.type == Common::EVENT_KEYUP)




More information about the Scummvm-git-logs mailing list