[Scummvm-git-logs] scummvm master -> 555669b87489152dfa82cbe9a9dc6c43c09381ef

OMGPizzaGuy noreply at scummvm.org
Tue Dec 6 23:32:54 UTC 2022


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:
555669b874 ULTIMA8: Avoid deleting the running process until after run completes.


Commit: 555669b87489152dfa82cbe9a9dc6c43c09381ef
    https://github.com/scummvm/scummvm/commit/555669b87489152dfa82cbe9a9dc6c43c09381ef
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2022-12-06T17:32:27-06:00

Commit Message:
ULTIMA8: Avoid deleting the running process until after run completes.

The game startup processes attempt to load a savegame which resets the kernel. Previously that running process could not properly perform any more tasks, such as proper termination, due to the pointer being deleted.

Changed paths:
    engines/ultima/ultima8/games/start_crusader_process.cpp
    engines/ultima/ultima8/games/start_u8_process.cpp
    engines/ultima/ultima8/kernel/kernel.cpp
    engines/ultima/ultima8/kernel/process.cpp


diff --git a/engines/ultima/ultima8/games/start_crusader_process.cpp b/engines/ultima/ultima8/games/start_crusader_process.cpp
index 29ba3beae0a..d942d4ce625 100644
--- a/engines/ultima/ultima8/games/start_crusader_process.cpp
+++ b/engines/ultima/ultima8/games/start_crusader_process.cpp
@@ -64,14 +64,16 @@ void StartCrusaderProcess::run() {
 		return;
 	}
 
-	// Try to load the save game, if succeeded this pointer will no longer be valid
+	// Try to load the save game, if succeeded this process will terminate
 	if (_saveSlot >= 0) {
 		Common::Error loadError = Ultima8Engine::get_instance()->loadGameState(_saveSlot);
 		if (loadError.getCode() != Common::kNoError) {
 			Ultima8Engine::get_instance()->setError(loadError);
+			fail();
 			return;
 		}
 
+		terminate();
 		return;
 	}
 
diff --git a/engines/ultima/ultima8/games/start_u8_process.cpp b/engines/ultima/ultima8/games/start_u8_process.cpp
index bed7cd44313..8ee01baff12 100644
--- a/engines/ultima/ultima8/games/start_u8_process.cpp
+++ b/engines/ultima/ultima8/games/start_u8_process.cpp
@@ -55,15 +55,17 @@ void StartU8Process::run() {
 		}
 	}
 
-	// Try to load the save game, if succeeded this pointer will no longer be valid
+	// Try to load the save game, if succeeded this process will terminate
 	if (_saveSlot >= 0) {
 		Common::Error loadError = Ultima8Engine::get_instance()->loadGameState(_saveSlot);
 		if (loadError.getCode() != Common::kNoError) {
 			Ultima8Engine::get_instance()->setError(loadError);
+			fail();
 			return;
 		}
 
 		PaletteFaderProcess::I_fadeFromBlack(0, 0);
+		terminate();
 		return;
 	}
 
diff --git a/engines/ultima/ultima8/kernel/kernel.cpp b/engines/ultima/ultima8/kernel/kernel.cpp
index aca185e1641..9dda85a4249 100644
--- a/engines/ultima/ultima8/kernel/kernel.cpp
+++ b/engines/ultima/ultima8/kernel/kernel.cpp
@@ -64,14 +64,14 @@ void Kernel::reset() {
 
 	for (ProcessIterator it = _processes.begin(); it != _processes.end(); ++it) {
 		Process *p = *it;
-		if (p->_flags & Process::PROC_TERM_DISPOSE) {
+		if (p->_flags & Process::PROC_TERM_DISPOSE && p != _runningProcess) {
 			delete p;
 		} else {
 			p->_flags |= Process::PROC_TERMINATED;
 		}
 	}
 	_processes.clear();
-	_currentProcess = _processes.begin();
+	_currentProcess = _processes.end();
 
 	_pIDs->clearAll();
 
@@ -168,6 +168,7 @@ void Kernel::runProcesses() {
 				(_paused || _tickNum % p->getTicksPerRun() == 0)) {
 			_runningProcess = p;
 			p->run();
+			_runningProcess = nullptr;
 
 			num_run++;
 
@@ -192,10 +193,13 @@ void Kernel::runProcesses() {
 				p->fail();
 			}
 
-			if (!_runningProcess)
-				return; // If this happens then the list was reset so leave NOW!
-
-			_runningProcess = nullptr;
+			if (_currentProcess == _processes.end()) {
+				// If this happens then the list was reset so delete the process and return.
+				if (p->_flags & Process::PROC_TERM_DISPOSE) {
+					delete p;
+				}
+				return;
+			}
 		}
 		if (!_paused && (p->_flags & Process::PROC_TERMINATED)) {
 			// process is killed, so remove it from the list
diff --git a/engines/ultima/ultima8/kernel/process.cpp b/engines/ultima/ultima8/kernel/process.cpp
index 962fcf61fc6..7aacb97ba54 100644
--- a/engines/ultima/ultima8/kernel/process.cpp
+++ b/engines/ultima/ultima8/kernel/process.cpp
@@ -38,8 +38,6 @@ Process::Process(ObjId it, uint16 ty)
 }
 
 void Process::fail() {
-	assert(!(_flags & PROC_TERMINATED));
-
 	_flags |= PROC_FAILED;
 	terminate();
 }




More information about the Scummvm-git-logs mailing list