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

Strangerke noreply at scummvm.org
Mon May 13 20:23:20 UTC 2024


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

Summary:
ccbbcb0d43 BAGEL: Introduce fatalError() to slowly move fatal errors from reportError to it, remove some unused stuff in error.h/pp
c934a2b66b BAGEL: Initialize variables in CNavWindow (CID 1544897), more work on fatalError


Commit: ccbbcb0d438e4076635047e28d54421a5e2cfde5
    https://github.com/scummvm/scummvm/commit/ccbbcb0d438e4076635047e28d54421a5e2cfde5
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-13T20:40:42+01:00

Commit Message:
BAGEL: Introduce fatalError() to slowly move fatal errors from reportError to it, remove some unused stuff in error.h/pp and string.h/cpp

Changed paths:
    engines/bagel/baglib/bagel.cpp
    engines/bagel/boflib/app.cpp
    engines/bagel/boflib/app.h
    engines/bagel/boflib/error.cpp
    engines/bagel/boflib/error.h
    engines/bagel/boflib/string.cpp
    engines/bagel/boflib/string.h
    engines/bagel/spacebar/spacebar.cpp
    engines/bagel/spacebar/sraf_computer.cpp
    engines/bagel/spacebar/vid_wnd.cpp


diff --git a/engines/bagel/baglib/bagel.cpp b/engines/bagel/baglib/bagel.cpp
index 6e76db43371..2b96d8611ee 100644
--- a/engines/bagel/baglib/bagel.cpp
+++ b/engines/bagel/baglib/bagel.cpp
@@ -59,10 +59,8 @@ CBagel::~CBagel() {
 	release();
 
 	// Empty the file cache.
-	if (_cacheFileList) {
-		delete _cacheFileList;
-		_cacheFileList = nullptr;
-	}
+	delete _cacheFileList;
+	_cacheFileList = nullptr;
 
 	_szAppName[0] = '\0';
 	_pMainWnd = nullptr;
@@ -174,10 +172,8 @@ ErrorCode CBagel::shutdown() {
 
 	// Just in case the child class forgot to delete the main window,
 	// I'll do it.
-	if (_pMainWnd != nullptr) {
-		delete _pMainWnd;
-		_pMainWnd = nullptr;
-	}
+	delete _pMainWnd;
+	_pMainWnd = nullptr;
 
 	return CBofApp::shutdown();
 }
diff --git a/engines/bagel/boflib/app.cpp b/engines/bagel/boflib/app.cpp
index 85a2e6b90de..d99ddbfcf1e 100644
--- a/engines/bagel/boflib/app.cpp
+++ b/engines/bagel/boflib/app.cpp
@@ -137,11 +137,11 @@ ErrorCode CBofApp::runApp() {
 			limiter.startFrame();
 			continue;
 
-		} else if (_consoleVideo) {
-			delete _consoleVideo;
-			_consoleVideo = nullptr;
 		}
 
+		delete _consoleVideo;
+		_consoleVideo = nullptr;
+
 		// Handle sounds and timers
 		CBofSound::audioTask();
 		CBofTimer::handleTimers();
@@ -187,25 +187,15 @@ ErrorCode CBofApp::shutdown() {
 }
 
 
-ErrorCode CBofApp::preShutDown() {
-	return _errCode;
-}
-
-ErrorCode CBofApp::postShutDown() {
-	if (_pWindow != nullptr) {
-		delete _pWindow;
-		_pWindow = nullptr;
-	}
+void CBofApp::postShutDown() {
+	delete _pWindow;
+	_pWindow = nullptr;
 
 	// No more palettes
 	_pPalette = nullptr;
 
-	if (_pDefPalette != nullptr) {
-		delete _pDefPalette;
-		_pDefPalette = nullptr;
-	}
-
-	return _errCode;
+	delete _pDefPalette;
+	_pDefPalette = nullptr;
 }
 
 void CBofApp::setPalette(CBofPalette *pPalette) {
diff --git a/engines/bagel/boflib/app.h b/engines/bagel/boflib/app.h
index bce2c0c3372..23c7e8477fc 100644
--- a/engines/bagel/boflib/app.h
+++ b/engines/bagel/boflib/app.h
@@ -70,8 +70,7 @@ public:
 	virtual ~CBofApp();
 
 	ErrorCode preInit();
-	ErrorCode preShutDown();
-	ErrorCode postShutDown();
+	void postShutDown();
 
 	// These functions can be overridden by the child class
 	virtual ErrorCode initialize();
diff --git a/engines/bagel/boflib/error.cpp b/engines/bagel/boflib/error.cpp
index 988fc4a0a89..48b6a97387c 100644
--- a/engines/bagel/boflib/error.cpp
+++ b/engines/bagel/boflib/error.cpp
@@ -40,16 +40,12 @@ const char *const g_errList[] = {
 	"Invalid Path",
 	"Disk error",
 	"Unknown Error",
-	"CRC failure",
-	"Not enough disk space",
-	"Future Use #15", // for future use
-	"Future Use #16", // for future use
-	"Future Use #17"  // for future use
+	"CRC failure"
 };
 
 // Static members
 //
-int CBofError::_nErrorCount;
+int CBofError::_count;
 
 
 CBofError::CBofError() {
@@ -57,7 +53,7 @@ CBofError::CBofError() {
 }
 
 void CBofError::initialize() {
-	_nErrorCount = 0;
+	_count = 0;
 }
 
 void CBofError::reportError(ErrorCode errCode, const char *format, ...) {
@@ -69,7 +65,7 @@ void CBofError::reportError(ErrorCode errCode, const char *format, ...) {
 	Common::String buf;
 
 	// One more error
-	_nErrorCount++;
+	_count++;
 
 	// Don't parse the variable input if there isn't any
 	if (format != nullptr) {
@@ -81,7 +77,7 @@ void CBofError::reportError(ErrorCode errCode, const char *format, ...) {
 	}
 
 	// Tell user about error, unless there were too many errors
-	if (_nErrorCount < MAX_ERRORS)
+	if (_count < MAX_ERRORS)
 		bofMessageBox(buf, g_errList[errCode]);
 
 	GUI::Debugger *console = g_engine->getDebugger();
@@ -89,4 +85,24 @@ void CBofError::reportError(ErrorCode errCode, const char *format, ...) {
 		console->debugPrintf("%s\n", buf.c_str());
 }
 
+void CBofError::fatalError(ErrorCode errCode, const char *format, ...) {
+	_errCode = errCode;
+
+	if (_errCode == ERR_NONE)
+		return;
+
+	Common::String buf;
+
+	// Don't parse the variable input if there isn't any
+	if (format != nullptr) {
+		// Parse the arguments
+		va_list argptr;
+		va_start(argptr, format);
+		buf = Common::String::vformat(format, argptr);
+		va_end(argptr);
+	}
+
+	error("%s - %s", g_errList[errCode] , buf.c_str());
+}
+
 } // namespace Bagel
diff --git a/engines/bagel/boflib/error.h b/engines/bagel/boflib/error.h
index 01057301ee4..b1169c1f995 100644
--- a/engines/bagel/boflib/error.h
+++ b/engines/bagel/boflib/error.h
@@ -43,19 +43,15 @@ enum ErrorCode {
 	ERR_CRC     = 13,   /* file or data failed CRC check */
 };
 
-#define NUM_ERR_CODES 18
 #define MAX_ERRORS 3
 
 extern const char *const g_errList[];
 
 class CBofError {
 protected:
-	static ErrorCode _errGlobal;
-	static int _nErrorCount;
-
+	static int _count;
 	ErrorCode _errCode;
 
-protected:
 	virtual void bofMessageBox(const Common::String &content, const Common::String &title) {}
 
 public:
@@ -71,6 +67,13 @@ public:
 	 */
 	void reportError(ErrorCode errCode, const char *format, ...);
 
+	/**
+	 * Logs specified fatal error to log file and exit the game.
+	 * @param errCode       Error to report
+	 * @param format        printf style format string
+	 */
+	void fatalError(ErrorCode errCode, const char *format, ...);
+
 	bool errorOccurred() {
 		return _errCode != ERR_NONE;
 	}
@@ -84,13 +87,7 @@ public:
 	static void initialize();
 
 	static int getErrorCount() {
-		return _nErrorCount;
-	}
-	static void setErrorCount(int nCount) {
-		_nErrorCount = nCount;
-	}
-	static void clearErrorCount() {
-		setErrorCount(0);
+		return _count;
 	}
 
 };
diff --git a/engines/bagel/boflib/string.cpp b/engines/bagel/boflib/string.cpp
index 2c145f4e493..f3575d01ee7 100644
--- a/engines/bagel/boflib/string.cpp
+++ b/engines/bagel/boflib/string.cpp
@@ -132,12 +132,6 @@ void CBofString::free() {
 	SETBUFFERSIZE(0, bStackMem);
 }
 
-void CBofString::safeDelete(char *pszBuf) {
-	if (pszBuf != nullptr) {
-		bofFree(pszBuf);
-	}
-}
-
 void CBofString::copy(const char *pszBuf) {
 	assert(isValidObject(this));
 
@@ -270,7 +264,7 @@ void CBofString::concatInPlace(int nSrcLen, const char *lpszSrcData) {
 				lpszOldData = new char[_nLength + nSrcLen + 1];
 
 			if (lpszOldData != nullptr) {
-				memcpy(lpszOldData, _pszData, (_nLength /*+ nSrcLen*/ + 1) * sizeof(char));
+				memcpy(lpszOldData, _pszData, (_nLength + 1) * sizeof(char));
 
 				concatCopy(_nLength, lpszOldData, nSrcLen, lpszSrcData, _nLength + nAllocAmount);
 
@@ -326,74 +320,17 @@ char *CBofString::getBuffer() {
 	return _pszData;
 }
 
-void CBofString::releaseBuffer(int nNewLength) {
-	assert(isValidObject(this));
-	assert(nNewLength >= 0);
-
-	if (_pszData != nullptr) {
-
-		_nLength = MIN<uint16>(nNewLength, _nLength);
-
-		_pszData[_nLength] = '\0';
-	}
-}
-
-void CBofString::freeExtra() {
-	assert(isValidObject(this));
-	assert(_nLength <= NORMALIZEBUFFERSIZE());
-
-	if (_nLength != NORMALIZEBUFFERSIZE()) {
-		char *pszOldData;
-
-		if ((pszOldData = new char[_nLength + 1]) != nullptr) {
-			Common::strlcpy(pszOldData, _pszData, 9999);
-
-			allocBuffer(_nLength);
-			Common::strlcpy(_pszData, pszOldData, 9999);
-			assert(_pszData[_nLength] == '\0');
-
-			delete[] pszOldData;
-		}
-	}
-	assert(_pszData != nullptr);
-}
-
-int CBofString::find(char ch) const {
-	assert(isValidObject(this));
-
-	// Find first single character
-	char *lpsz = nullptr;
-
-	if (_pszData != nullptr)
-		lpsz = strchr(_pszData, ch);
-
-	// Return -1 if not found and index otherwise
-	return (lpsz == nullptr) ? -1 : (int)(lpsz - _pszData);
-}
-
-int CBofString::findOneOf(const char *lpszCharSet) const {
-	assert(isValidObject(this));
-
-	char *lpsz = nullptr;
-	if (_pszData != nullptr)
-		lpsz = strpbrk(_pszData, lpszCharSet);
-
-	return (lpsz == nullptr) ? -1 : (int)(lpsz - _pszData);
-}
-
 int CBofString::findNumOccurrences(const char *pszSub) {
 	assert(isValidObject(this));
 	assert(pszSub != nullptr);
 	assert(*pszSub != '\0');
 
-	char *pszCur;
-	int nHits;
-
-	nHits = 0;
+	int nHits = 0;
 	if (_pszData != nullptr) {
-		pszCur = _pszData;
+		char *pszCur = _pszData;
 		while (pszCur != nullptr) {
-			if ((pszCur = strstr(pszCur, pszSub)) != nullptr) {
+			pszCur = strstr(pszCur, pszSub);
+			if (pszCur != nullptr) {
 				nHits++;
 				pszCur++;
 			}
@@ -449,29 +386,6 @@ CBofString CBofString::mid(int nFirst, int nCount) const {
 	return dest;
 }
 
-void CBofString::mid(int nFirst, CBofString *mStr) const {
-	assert(isValidObject(this));
-	mid(nFirst, _nLength - nFirst, mStr);
-}
-
-void CBofString::mid(int nFirst, int nCount, CBofString *mStr) const {
-	assert(isValidObject(this));
-	assert(mStr != nullptr);
-
-	assert(nFirst >= 0);
-	assert(nCount >= 0);
-
-	// Out-of-bounds requests return sensible things
-	if (nFirst + nCount > _nLength)
-		nCount = _nLength - nFirst;
-	if (nFirst > _nLength)
-		nCount = 0;
-
-	*mStr = *this;
-	memcpy(mStr->_pszData, &_pszData[nFirst], nCount);
-	mStr->_nLength = (uint16)nCount;
-}
-
 CBofString CBofString::right(int nCount) const {
 	assert(isValidObject(this));
 
@@ -485,19 +399,6 @@ CBofString CBofString::right(int nCount) const {
 	return dest;
 }
 
-void CBofString::right(int nCount, CBofString *rStr) const {
-	assert(isValidObject(this));
-
-	assert(nCount >= 0);
-
-	if (nCount > _nLength)
-		nCount = _nLength;
-
-	*rStr = *this;
-	memcpy(rStr->_pszData, &_pszData[_nLength - nCount], nCount);
-	rStr->_nLength = (uint16)nCount;
-}
-
 CBofString CBofString::left(int nCount) const {
 	assert(isValidObject(this));
 
@@ -511,18 +412,6 @@ CBofString CBofString::left(int nCount) const {
 	return dest;
 }
 
-void CBofString::left(int nCount, CBofString *lStr) const {
-	assert(isValidObject(this));
-
-	assert(nCount >= 0);
-
-	if (nCount > _nLength)
-		nCount = _nLength;
-
-	*lStr = *this;
-	lStr->_nLength = (uint16)nCount;
-}
-
 void CBofString::deleteLastChar() {
 	if (!isEmpty()) {
 		*(_pszData + _nLength - 1) = '\0';
@@ -530,43 +419,6 @@ void CBofString::deleteLastChar() {
 	}
 }
 
-// strspn equivalent
-CBofString CBofString::spanIncluding(const char *lpszCharSet) const {
-	assert(isValidObject(this));
-
-	int n = 0;
-
-	if (_pszData != nullptr)
-		n = strspn(_pszData, lpszCharSet);
-
-	return left(n);
-}
-
-// strcspn equivalent
-CBofString CBofString::spanExcluding(const char *lpszCharSet) const {
-	assert(isValidObject(this));
-
-	int n = 0;
-
-	if (_pszData != nullptr)
-		n = strcspn(_pszData, lpszCharSet);
-
-	return left(n);
-}
-
-int CBofString::reverseFind(char ch) const {
-	assert(isValidObject(this));
-
-	// Find last single character
-	char *lpsz = nullptr;
-
-	if (_pszData != nullptr)
-		lpsz = strrchr(_pszData, ch);
-
-	// Return -1 if not found, distance from beginning otherwise
-	return (lpsz == nullptr) ? -1 : (int)(lpsz - _pszData);
-}
-
 // Find a sub-string (like strstr)
 int CBofString::find(const char *lpszSub) const {
 	assert(isValidObject(this));
@@ -586,34 +438,6 @@ int CBofString::find(const char *lpszSub) const {
 #define FORCE_ANSI 0x10000
 #define FORCE_UNICODE 0x20000
 
-// Formatting (using wsprintf style formatting)
-void CBofString::format(const char *lpszFormat, ...) {
-	assert(isValidObject(this));
-
-	va_list argptr;
-
-	assert(lpszFormat != nullptr);
-
-	//
-	// Don't parse the variable input if there aren't any
-	//
-	if (lpszFormat != nullptr) {
-		//
-		// Parse the variable argument list
-		//
-		char szBuf[MAX_STRING];
-		va_start(argptr, lpszFormat);
-		Common::vsprintf_s(szBuf, lpszFormat, argptr);
-		va_end(argptr);
-
-		/* Make sure we didn't blow the stack */
-		assert(strlen(szBuf) < MAX_STRING);
-
-		allocBuffer(strlen(szBuf));
-		Common::strcpy_s(_pszData, MAX_STRING, szBuf);
-	}
-}
-
 int CBofString::safeStrlen(const char *psz) {
 	return (psz == nullptr) ? 0 : strlen(psz);
 }
@@ -643,12 +467,6 @@ int CBofString::compareNoCase(const char *psz) const {
 	return n;
 }
 
-int CBofString::collate(const char *psz) const {
-	assert(isValidObject(this));
-
-	return strcoll(_pszData, psz);
-}
-
 char CBofString::getAt(int nIndex) {
 	assert(isValidObject(this));
 
@@ -664,18 +482,6 @@ char CBofString::operator[](int nIndex) {
 	return getAt(nIndex);
 }
 
-void CBofString::setAt(int nIndex, char ch) {
-	assert(isValidObject(this));
-
-	assert(nIndex >= 0);
-	assert(nIndex < _nLength);
-	assert(ch != 0);
-
-	if (_pszData != nullptr) {
-		_pszData[nIndex] = ch;
-	}
-}
-
 void CBofString::replaceCharAt(int nIndex, char chNew) {
 	if (_pszData != nullptr && nIndex < _nLength) {
 		_pszData[nIndex] = chNew;
@@ -802,11 +608,4 @@ void CBofString::makeUpper() {
 	strncpy(_pszData, s.c_str(), _nLength);
 }
 
-void CBofString::makeLower() {
-	Common::String s(_pszData);
-	s.toLowercase();
-
-	strncpy(_pszData, s.c_str(), _nLength);
-}
-
 } // namespace Bagel
diff --git a/engines/bagel/boflib/string.h b/engines/bagel/boflib/string.h
index 70764c334bc..309786ec475 100644
--- a/engines/bagel/boflib/string.h
+++ b/engines/bagel/boflib/string.h
@@ -101,7 +101,6 @@ public:
 
 	char getAt(int nIndex);      // 0 based
 	char operator[](int nIndex); // same as getAt
-	void setAt(int nIndex, char ch);
 
 	operator const char *() const {
 		return (const char *)_pszData;
@@ -139,7 +138,6 @@ public:
 	// String comparison
 	int compare(const char *lpsz) const;       // straight character
 	int compareNoCase(const char *lpsz) const; // ignore case
-	int collate(const char *lpsz) const;       // NLS aware
 
 	// Simple sub-string extraction
 	//
@@ -148,26 +146,12 @@ public:
 	CBofString left(int nCount) const;
 	CBofString right(int nCount) const;
 
-	void mid(int nFirst, int nCount, CBofString *) const;
-	void mid(int nFirst, CBofString *) const;
-	void left(int nCount, CBofString *) const;
-	void right(int nCount, CBofString *) const;
-
 	void deleteLastChar();
 
-	CBofString spanIncluding(const char *lpszCharSet) const;
-	CBofString spanExcluding(const char *lpszCharSet) const;
-
 	// Upper/lower/reverse conversion
 	void makeUpper();
-	void makeLower();
 
 	// Searching (return starting index, or -1 if not found)
-	// look for a single character match
-	int find(char ch) const; // like "C" strchr
-	int reverseFind(char ch) const;
-	int findOneOf(const char *lpszCharSet) const;
-
 	// Look for a specific sub-string
 	int find(const char *lpszSub) const; // like "C" strstr
 	int findNumOccurrences(const char *pszSub);
@@ -177,13 +161,8 @@ public:
 	void replaceChar(char chOld, char chNew);
 	void replaceStr(const char *pszOld, const char *pszNew);
 
-	// Simple formatting
-	void format(const char *lpszFormat, ...);
-
 	// Access to string implementation buffer as "C" character array
 	char *getBuffer();
-	void releaseBuffer(int nNewLength = 0);
-	void freeExtra();
 
 protected:
 	// implementation helpers
@@ -206,7 +185,6 @@ protected:
 
 	void concatCopy(int nSrc1Len, const char *lpszSrc1Data, int nSrc2Len, const char *lpszSrc2Data, int nAllocLen = 0);
 	void concatInPlace(int nSrcLen, const char *lpszSrcData);
-	static void safeDelete(char *lpsz);
 	static int safeStrlen(const char *lpsz);
 
 	// Lengths/sizes in characters
diff --git a/engines/bagel/spacebar/spacebar.cpp b/engines/bagel/spacebar/spacebar.cpp
index adb040487cf..7fee6146dd8 100644
--- a/engines/bagel/spacebar/spacebar.cpp
+++ b/engines/bagel/spacebar/spacebar.cpp
@@ -258,7 +258,6 @@ Common::Error SpaceBarEngine::run() {
 		runApp();
 
 	// shutdown
-	preShutDown();
 	shutdown();
 	postShutDown();
 
diff --git a/engines/bagel/spacebar/sraf_computer.cpp b/engines/bagel/spacebar/sraf_computer.cpp
index f63e5bc94b6..6d4afa3e2b3 100644
--- a/engines/bagel/spacebar/sraf_computer.cpp
+++ b/engines/bagel/spacebar/sraf_computer.cpp
@@ -4172,28 +4172,30 @@ void SrafComputer::notifyBoss(CBofString &sSoundFile, int nStafferID) {
 	// Play the voice file... Depends on if we have a voice file or a text file...
 	// the last three will tell us.
 
-	if (sSoundFile.find(".WAV") != -1 ||
-	        sSoundFile.find(".wav") != -1) {
+	if (sSoundFile.find(".WAV") != -1 || sSoundFile.find(".wav") != -1) {
 		CBofCursor::hide();
 		BofPlaySound(sSoundFile.getBuffer(), SOUND_WAVE);
 		CBofCursor::show();
 	} else if (sSoundFile.find(".TXT") || sSoundFile.find(".txt")) {
 		// Make sure the file is there, read it in to our own buffer.
 		CBofFile fTxtFile(sSoundFile, CBF_BINARY | CBF_READONLY);
-		char *pszBuf;
-		int nLength = fTxtFile.getLength();
+		uint32 nLength = fTxtFile.getLength();
+
+		if (nLength == 0) {
+			reportError(ERR_FREAD, "Unexpected empty file %s", sSoundFile.getBuffer());
+		} else {
+			char *pszBuf = (char *)bofAlloc(nLength + 1);
+			if (pszBuf == nullptr)
+				fatalError(ERR_MEMORY, "Could not allocate a buffer of %u bytes", nLength + 1);
 
-		if (nLength != 0 && (pszBuf = (char *)bofAlloc(nLength + 1)) != nullptr) {
 			memset(pszBuf, 0, nLength + 1);
 			fTxtFile.read(pszBuf, nLength);
 
 			// Put it up on the screen
 			displayMessage(pszBuf);
 			bofFree(pszBuf);
-			fTxtFile.close();
-		} else {
-			reportError(ERR_MEMORY, "Could not read %s into memory", sSoundFile.getBuffer());
 		}
+		fTxtFile.close();
 	}
 
 	// allow for no staffer screen
@@ -4614,14 +4616,13 @@ int SrafTextScreen::createTextScreen(CBofWindow *pParent) {
 	cRect.setRect(gCompDisplay.left, gCompDisplay.top, gCompDisplay.right, gCompDisplay.bottom);
 
 	_pTextBox = new CBofTextBox(this, &cRect, _text);
-	if (_pTextBox != nullptr) {
-		_pTextBox->setPageLength(24);
-		_pTextBox->setColor(CTEXT_WHITE);
-		_pTextBox->setFont(FONT_MONO);
-		_pTextBox->setPointSize(FONT_14POINT);
-	} else {
-		reportError(ERR_MEMORY, "Unable to allocate a CBofTextBox");
-	}
+	if (_pTextBox == nullptr)
+		fatalError(ERR_MEMORY, "Unable to allocate a CBofTextBox");
+
+	_pTextBox->setPageLength(24);
+	_pTextBox->setColor(CTEXT_WHITE);
+	_pTextBox->setFont(FONT_MONO);
+	_pTextBox->setPointSize(FONT_14POINT);
 
 	return ERR_NONE;
 }
diff --git a/engines/bagel/spacebar/vid_wnd.cpp b/engines/bagel/spacebar/vid_wnd.cpp
index a0b95d9f981..9e0a5b0a768 100644
--- a/engines/bagel/spacebar/vid_wnd.cpp
+++ b/engines/bagel/spacebar/vid_wnd.cpp
@@ -107,14 +107,12 @@ ErrorCode SBarVidWnd::attach() {
 		}
 
 		_pMovie = new CBagCharacterObject;
-		if (_pMovie != nullptr) {
-			_pMovie->setFileName(BuildVidDir("BRNL.SMK"));
-			_pMovie->setPosition(CBofPoint(209, 10));
-			_pMovie->attach();
+		if (_pMovie == nullptr)
+			fatalError(ERR_MEMORY, "Unable to allocate a CBagCharacterObject");
 
-		} else {
-			reportError(ERR_MEMORY, "Unable to allocate a CBagCharacterObject");
-		}
+		_pMovie->setFileName(BuildVidDir("BRNL.SMK"));
+		_pMovie->setPosition(CBofPoint(209, 10));
+		_pMovie->attach();
 
 		_fTimerDiff = 0;
 


Commit: c934a2b66b3f65b49c7f2efb4e7bafa90dd1fc4d
    https://github.com/scummvm/scummvm/commit/c934a2b66b3f65b49c7f2efb4e7bafa90dd1fc4d
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-13T21:23:10+01:00

Commit Message:
BAGEL: Initialize variables in CNavWindow (CID 1544897), more work on fatalError

Changed paths:
    engines/bagel/spacebar/nav_window.cpp
    engines/bagel/spacebar/nav_window.h
    engines/bagel/spacebar/slot_wnd.cpp
    engines/bagel/spacebar/spacebar.cpp


diff --git a/engines/bagel/spacebar/nav_window.cpp b/engines/bagel/spacebar/nav_window.cpp
index 875ba1d10be..7fd5b03eb1f 100644
--- a/engines/bagel/spacebar/nav_window.cpp
+++ b/engines/bagel/spacebar/nav_window.cpp
@@ -146,7 +146,6 @@ CNavWindow::CNavWindow() {
 	_pOldPal = nullptr;
 	_pMap = nullptr;
 	_pCurLoc = nullptr;
-	//  _pLevelDone = nullptr;
 	_pNewMap = nullptr;
 	_pCurPos = nullptr;
 	_pPortName = nullptr;
@@ -178,6 +177,12 @@ CNavWindow::CNavWindow() {
 	_pBattlefish = nullptr;
 	_pNoVacancy = nullptr;
 	_bNavAttached = false;
+
+	_bmptwo = nullptr;
+	_fuel = 40;
+	_cargo = 0;
+	_ship = 120;
+	_pLevel = nullptr;
 }
 
 ErrorCode CNavWindow::attach() {
@@ -259,35 +264,30 @@ ErrorCode CNavWindow::attach() {
 	_pPal = _pBackdrop->getPalette()->copyPalette();
 	CBofApp::getApp()->setPalette(_pPal);
 	_pCurLoc = new CBofSprite;
-	if (_pCurLoc != nullptr) {
-		_pCurLoc->loadSprite(makeDir(CUR_LOC), 2);
-		_pCurLoc->setMaskColor(MASK_COLOR);
-		_pCurLoc->setZOrder(SPRITE_TOPMOST);
-		_pCurLoc->setAnimated(true);
-		_pCurLoc->linkSprite();
-		_pCurLoc->setPosition(_pCurPos->left, _pCurPos->top);
+	if (_pCurLoc == nullptr)
+		fatalError(ERR_MEMORY, "Unable to allocate a CBofSprite");
 
-	} else {
-		reportError(ERR_MEMORY, "Unable to allocate a CBofSprite");
-	}
+	_pCurLoc->loadSprite(makeDir(CUR_LOC), 2);
+	_pCurLoc->setMaskColor(MASK_COLOR);
+	_pCurLoc->setZOrder(SPRITE_TOPMOST);
+	_pCurLoc->setAnimated(true);
+	_pCurLoc->linkSprite();
+	_pCurLoc->setPosition(_pCurPos->left, _pCurPos->top);
 
 	// Build all our buttons
 	for (i = 0; i < 2; i++) {
 		_pButtons[i] = new CBofBmpButton;
-		if (_pButtons[i] != nullptr) {
+		if (_pButtons[i] == nullptr)
+			fatalError(ERR_MEMORY, "Unable to allocate a CBofBmpButton");
 
-			CBofBitmap *pUp = loadBitmap(makeDir(g_navButtons[i]._pszUp), _pPal);
-			CBofBitmap *pDown = loadBitmap(makeDir(g_navButtons[i]._pszDown), _pPal);
-			CBofBitmap *pFocus = loadBitmap(makeDir(g_navButtons[i]._pszFocus), _pPal);
-			CBofBitmap *pDis = loadBitmap(makeDir(g_navButtons[i]._pszDisabled), _pPal);
+		CBofBitmap *pUp = loadBitmap(makeDir(g_navButtons[i]._pszUp), _pPal);
+		CBofBitmap *pDown = loadBitmap(makeDir(g_navButtons[i]._pszDown), _pPal);
+		CBofBitmap *pFocus = loadBitmap(makeDir(g_navButtons[i]._pszFocus), _pPal);
+		CBofBitmap *pDis = loadBitmap(makeDir(g_navButtons[i]._pszDisabled), _pPal);
 
-			_pButtons[i]->loadBitmaps(pUp, pDown, pFocus, pDis);
-			_pButtons[i]->create(g_navButtons[i]._pszName, g_navButtons[i]._nLeft, g_navButtons[i]._nTop, g_navButtons[i]._nWidth, g_navButtons[i]._nHeight, this, g_navButtons[i]._nID);
-			_pButtons[i]->show();
-		} else {
-			reportError(ERR_MEMORY, "Unable to allocate a CBofBmpButton");
-			break;
-		}
+		_pButtons[i]->loadBitmaps(pUp, pDown, pFocus, pDis);
+		_pButtons[i]->create(g_navButtons[i]._pszName, g_navButtons[i]._nLeft, g_navButtons[i]._nTop, g_navButtons[i]._nWidth, g_navButtons[i]._nHeight, this, g_navButtons[i]._nID);
+		_pButtons[i]->show();
 	}
 
 	show();
@@ -1319,8 +1319,8 @@ void CNavWindow::calcFuel(double hf) {
 			CBofString sNebDir(NEBSIM4_BMP);
 			MACROREPLACE(sNebDir);
 			assert(_pBackdrop != nullptr);
-			bmptwo = new CBofBitmap(sNebDir.getBuffer(), _pPal);
-			setBackground(bmptwo);
+			_bmptwo = new CBofBitmap(sNebDir.getBuffer(), _pPal);
+			setBackground(_bmptwo);
 			_cargo = 125 + 10 + 17 + 8 + 99 + 24;
 			_ship = 65;
 			_fuel = 45;
@@ -1337,8 +1337,8 @@ void CNavWindow::calcFuel(double hf) {
 			CBofString sNebDir(NEBSIM3_BMP);
 			MACROREPLACE(sNebDir);
 			assert(_pBackdrop != nullptr);
-			bmptwo = new CBofBitmap(sNebDir.getBuffer(), _pPal);
-			setBackground(bmptwo);
+			_bmptwo = new CBofBitmap(sNebDir.getBuffer(), _pPal);
+			setBackground(_bmptwo);
 			_cargo = 100 + 75 + 28 + 45 + 14;
 			_ship = 99;
 			_fuel = 36;
@@ -1355,8 +1355,8 @@ void CNavWindow::calcFuel(double hf) {
 			CBofString sNebDir(NEBSIM2_BMP);
 			MACROREPLACE(sNebDir);
 			assert(_pBackdrop != nullptr);
-			bmptwo = new CBofBitmap(sNebDir.getBuffer(), _pPal);
-			setBackground(bmptwo);
+			_bmptwo = new CBofBitmap(sNebDir.getBuffer(), _pPal);
+			setBackground(_bmptwo);
 			_cargo = 54 + 119 + 20 + 127;
 			_ship = 120;
 			_fuel = 75;
diff --git a/engines/bagel/spacebar/nav_window.h b/engines/bagel/spacebar/nav_window.h
index d26b7b224b7..b5c8b6a7855 100644
--- a/engines/bagel/spacebar/nav_window.h
+++ b/engines/bagel/spacebar/nav_window.h
@@ -127,7 +127,7 @@ protected:
 	CBofSprite *_pMap;
 	CBofSprite *_pCurLoc;
 	CBofBitmap *_pNewMap;
-	CBofBitmap *bmptwo;
+	CBofBitmap *_bmptwo;
 	CBofRect *_pCurPos;
 	CBofString *_pPortName;
 	CBofRect *_pWilbur;
diff --git a/engines/bagel/spacebar/slot_wnd.cpp b/engines/bagel/spacebar/slot_wnd.cpp
index 1d058f586aa..97e20935f3d 100644
--- a/engines/bagel/spacebar/slot_wnd.cpp
+++ b/engines/bagel/spacebar/slot_wnd.cpp
@@ -175,10 +175,8 @@ ErrorCode  SBarSlotWnd::attach() {
 	_bFixBet = false;
 
 	_pSlotSound = new CBofSound(this, BuildSlotDir(SLOT_AUDIO), SOUND_MIX, 1);
-	if (_pSlotSound == nullptr) {
-		reportError(ERR_MEMORY, "Unable to allocate a CBofSound");
-	}
-
+	if (_pSlotSound == nullptr)
+		fatalError(ERR_MEMORY, "Unable to allocate a CBofSound");
 
 	if (CBagStorageDevWnd::attach() == ERR_NONE) {
 		// Must have a valid backdrop by now
@@ -206,7 +204,7 @@ ErrorCode  SBarSlotWnd::attach() {
 		if (_pLoseBmp == nullptr) {
 			_pLoseBmp = new CBofBitmap(BuildSlotDir("BGNV.BMP"), pPal);
 			if (_pLoseBmp == nullptr) {
-				reportError(ERR_MEMORY, "Unable to allocate a CBofBitmap");
+				fatalError(ERR_MEMORY, "Unable to allocate a CBofBitmap");
 			}
 		}
 
@@ -234,16 +232,15 @@ ErrorCode  SBarSlotWnd::attach() {
 
 		// Setup the Credit text fields
 		_pCredText = new CBofText;
-		if (_pCredText != nullptr) {
-			CBofRect cRect(CreditRect.left, CreditRect.top, CreditRect.right, CreditRect.bottom);
-			_pCredText->setupText(&cRect, JUSTIFY_RIGHT, FORMAT_CENTER_RIGHT);
-			_pCredText->setColor(CTEXT_WHITE);
-			_pCredText->SetSize(20);
-			_pCredText->setWeight(TEXT_BOLD);
-			_pCredText->setText(buildString("%d", _nCredit));
-		} else {
-			reportError(ERR_MEMORY, "Unable to allocate a CBofText");
-		}
+		if (_pCredText == nullptr)
+			fatalError(ERR_MEMORY, "Unable to allocate a CBofText");
+
+		CBofRect cRect(CreditRect.left, CreditRect.top, CreditRect.right, CreditRect.bottom);
+		_pCredText->setupText(&cRect, JUSTIFY_RIGHT, FORMAT_CENTER_RIGHT);
+		_pCredText->setColor(CTEXT_WHITE);
+		_pCredText->SetSize(20);
+		_pCredText->setWeight(TEXT_BOLD);
+		_pCredText->setText(buildString("%d", _nCredit));
 
 		// Setup the Bet text fields
 		//
@@ -251,16 +248,15 @@ ErrorCode  SBarSlotWnd::attach() {
 		assert(_pBetText == nullptr);
 
 		_pBetText = new CBofText;
-		if (_pBetText != nullptr) {
-			CBofRect cRect(BetRect.left, BetRect.top, BetRect.right, BetRect.bottom);
-			_pBetText->setupText(&cRect, JUSTIFY_RIGHT, FORMAT_CENTER_RIGHT);
-			_pBetText->setColor(CTEXT_WHITE);
-			_pBetText->SetSize(20);
-			_pBetText->setWeight(TEXT_BOLD);
-			_pBetText->setText(buildString("%d", _nBet));
-		} else {
-			reportError(ERR_MEMORY, "Unable to allocate a CBofText");
-		}
+		if (_pBetText == nullptr)
+			fatalError(ERR_MEMORY, "Unable to allocate a CBofText");
+
+		cRect.setRect(BetRect.left, BetRect.top, BetRect.right, BetRect.bottom);
+		_pBetText->setupText(&cRect, JUSTIFY_RIGHT, FORMAT_CENTER_RIGHT);
+		_pBetText->setColor(CTEXT_WHITE);
+		_pBetText->SetSize(20);
+		_pBetText->setWeight(TEXT_BOLD);
+		_pBetText->setText(buildString("%d", _nBet));
 
 		// Setup the Odds text fields
 		//
@@ -268,30 +264,26 @@ ErrorCode  SBarSlotWnd::attach() {
 		assert(_pOddsText == nullptr);
 
 		_pOddsText = new CBofText;
-		if (_pOddsText != nullptr) {
-			CBofRect cRect(OddRect.left, OddRect.top, OddRect.right, OddRect.bottom);
-			_pOddsText->setupText(&cRect, JUSTIFY_RIGHT, FORMAT_CENTER_RIGHT);
-			_pOddsText->setColor(CTEXT_WHITE);
-
-			_pOddsText->SetSize(32);
-			_pOddsText->setWeight(TEXT_BOLD);
-			_pOddsText->setText("");
-		} else {
-			reportError(ERR_MEMORY, "Unable to allocate a CBofText");
-		}
+		if (_pOddsText == nullptr)
+			fatalError(ERR_MEMORY, "Unable to allocate a CBofText");
+
+		cRect.setRect(OddRect.left, OddRect.top, OddRect.right, OddRect.bottom);
+		_pOddsText->setupText(&cRect, JUSTIFY_RIGHT, FORMAT_CENTER_RIGHT);
+		_pOddsText->setColor(CTEXT_WHITE);
+		_pOddsText->SetSize(32);
+		_pOddsText->setWeight(TEXT_BOLD);
+		_pOddsText->setText("");
 
 		show();
-
 		invalidateRect(nullptr);
 		updateWindow();
 	}
 
 	_pBkgSnd = new CBofSound(this, BuildSlotDir(CASINO_AUDIO), SOUND_MIX, 99999);
-	if (_pBkgSnd != nullptr) {
-		_pBkgSnd->play();
-	} else {
-		reportError(ERR_MEMORY, "Unable to allocate a CBofSound");
-	}
+	if (_pBkgSnd == nullptr)
+		fatalError(ERR_MEMORY, "Unable to allocate a CBofSound");
+
+	_pBkgSnd->play();
 
 	CBofCursor::show();
 
@@ -326,10 +318,8 @@ ErrorCode SBarSlotWnd::detach() {
 
 	// Destroy all buttons
 	for (int i = 0; i < NUM_SLOTBUTT; i++) {
-		if (_pSlotButs[i] != nullptr) {
-			delete _pSlotButs[i];
-			_pSlotButs[i] = nullptr;
-		}
+		delete _pSlotButs[i];
+		_pSlotButs[i] = nullptr;
 	}
 
 	// Destroy all our slotbmp
@@ -337,10 +327,8 @@ ErrorCode SBarSlotWnd::detach() {
 		_cSlots[i]._nIdx = 0;
 
 		for (int j = 0; j < SLOT_BMP_NUM; j++) {
-			if (_cSlots[i]._pSlotBmp[j]) {
-				delete _cSlots[i]._pSlotBmp[j];
-				_cSlots[i]._pSlotBmp[j] = nullptr;
-			}
+			delete _cSlots[i]._pSlotBmp[j];
+			_cSlots[i]._pSlotBmp[j] = nullptr;
 		}
 	}
 
@@ -458,7 +446,6 @@ void SBarSlotWnd::go() {
 	}
 
 	slideSlots();
-
 	calcOutcome();
 
 	// Hide the GO button
@@ -468,8 +455,8 @@ void SBarSlotWnd::go() {
 		g_bFix = true;
 
 	updateText();
-
 	updateWindow();
+
 	g_bFix = false;
 
 	if (_bFixBet && _nBet != 0) {
@@ -536,11 +523,10 @@ void SBarSlotWnd::calcOutcome() {
 	if (_nPayOff1 > 0) {
 		// Play winning audio
 		_pWinSound = new CBofSound(this, BuildSlotDir(WIN_AUDIO), SOUND_MIX, 1);
-		if (_pWinSound != nullptr) {
-			_pWinSound->play();
-		} else {
-			reportError(ERR_MEMORY, "Unable to allocate a CBofSound");
-		}
+		if (_pWinSound == nullptr)
+			fatalError(ERR_MEMORY, "Unable to allocate a CBofSound");
+
+		_pWinSound->play();
 
 		// Calc new credit
 		_nCredit += (_nBet * _nPayOff1) / _nPayOff2;
diff --git a/engines/bagel/spacebar/spacebar.cpp b/engines/bagel/spacebar/spacebar.cpp
index 7fee6146dd8..65c9784a9d7 100644
--- a/engines/bagel/spacebar/spacebar.cpp
+++ b/engines/bagel/spacebar/spacebar.cpp
@@ -89,121 +89,118 @@ ErrorCode SpaceBarEngine::initialize() {
 		bool bShowLogo = true;
 
 		_masterWin = new CSBarMasterWin();
-		if (_masterWin != nullptr) {
-			// This is the primary game window
-			setMainWindow(_masterWin);
-
-			// Init sound system
-			InitializeSoundSystem(1, 22050, 8);
-
-			pBmp = new CBofBitmap(_masterWin->width(), _masterWin->height(), _pPalette);
-			if (pBmp != nullptr) {
-				pBmp->fillRect(nullptr, COLOR_BLACK);
-			} else {
-				reportError(ERR_MEMORY, "Unable to allocate a CBofBitmap");
-			}
+		
+		if (_masterWin == nullptr)
+			fatalError(ERR_MEMORY, "Unable to allocate the main SpaceBar Window");
 
-			_masterWin->show();
-			_masterWin->validateRect(nullptr);
+		// This is the primary game window
+		setMainWindow(_masterWin);
 
-			// Paint the screen black
-			if (pBmp != nullptr)
-				pBmp->paint(_masterWin, 0, 0);
+		// Init sound system
+		InitializeSoundSystem(1, 22050, 8);
 
-			_useOriginalSaveLoad = ConfMan.getBool("original_menus");
+		pBmp = new CBofBitmap(_masterWin->width(), _masterWin->height(), _pPalette);
+		if (pBmp == nullptr)
+			fatalError(ERR_MEMORY, "Unable to allocate a CBofBitmap");
 
-			bool bRestart = true;
-			int saveSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1;
+		pBmp->fillRect(nullptr, COLOR_BLACK);
 
-			if (saveSlot != -1) {
-				bRestart = loadGameState(saveSlot).getCode() != Common::kNoError;
+		_masterWin->show();
+		_masterWin->validateRect(nullptr);
 
-			} else if (savesExist()) {
-				bRestart = false;
+		// Paint the screen black
+		pBmp->paint(_masterWin, 0, 0);
 
-				CBagStartDialog cDlg(buildSysDir("START.BMP"), _masterWin);
+		_useOriginalSaveLoad = ConfMan.getBool("original_menus");
 
-				CBofWindow *pLastWin = g_hackWindow;
-				g_hackWindow = &cDlg;
+		bool bRestart = true;
+		int saveSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1;
 
-				int nRetVal = cDlg.doModal();
+		if (saveSlot != -1) {
+			bRestart = loadGameState(saveSlot).getCode() != Common::kNoError;
 
-				g_hackWindow = pLastWin;
+		} else if (savesExist()) {
+			bRestart = false;
 
-				switch (nRetVal) {
-				case RESTORE_BTN:
-					break;
+			CBagStartDialog cDlg(buildSysDir("START.BMP"), _masterWin);
 
-				case RESTART_BTN:
-					bRestart = true;
+			CBofWindow *pLastWin = g_hackWindow;
+			g_hackWindow = &cDlg;
 
-					// Hide that dialog
-					if (pBmp != nullptr) {
-						pBmp->paint(_masterWin, 0, 0);
-					}
-					break;
+			int nRetVal = cDlg.doModal();
+
+			g_hackWindow = pLastWin;
+
+			switch (nRetVal) {
+			case RESTORE_BTN:
+				break;
+
+			case RESTART_BTN:
+				bRestart = true;
+
+				// Hide that dialog
+				if (pBmp != nullptr) {
+					pBmp->paint(_masterWin, 0, 0);
+				}
+				break;
+
+			case QUIT_BTN:
+				// Hide that dialog
+				if (pBmp != nullptr) {
+					pBmp->paint(_masterWin, 0, 0);
+				}
+				_masterWin->close();
+				_masterWin = nullptr;
+				break;
+			}
+		}
+
+		if (bRestart) {
+			// Should we show the intro movies?
+			getOption("Startup", "ShowLogo", &bShowLogo, true);
 
-				case QUIT_BTN:
-					// Hide that dialog
+			// Play intro movies, logo screens, etc...
+			if (bShowLogo) {
+				CBofString cString(SMK_LOGO1);
+				MACROREPLACE(cString);
+
+				// Play the movie only if it exists
+				if (fileExists(cString.getBuffer())) {
+					bofPlayMovie(_masterWin, cString.getBuffer());
 					if (pBmp != nullptr) {
 						pBmp->paint(_masterWin, 0, 0);
 					}
-					_masterWin->close();
-					_masterWin = nullptr;
-					break;
 				}
-			}
+				if (shouldQuit())
+					goto exit;
 
-			if (bRestart) {
-				// Should we show the intro movies?
-				getOption("Startup", "ShowLogo", &bShowLogo, true);
-
-				// Play intro movies, logo screens, etc...
-				if (bShowLogo) {
-					CBofString cString(SMK_LOGO1);
-					MACROREPLACE(cString);
-
-					// Play the movie only if it exists
-					if (fileExists(cString.getBuffer())) {
-						bofPlayMovie(_masterWin, cString.getBuffer());
-						if (pBmp != nullptr) {
-							pBmp->paint(_masterWin, 0, 0);
-						}
-					}
-					if (shouldQuit())
-						goto exit;
-
-					cString = SMK_LOGO2;
-					MACROREPLACE(cString);
-					if (fileExists(cString.getBuffer())) {
-						bofPlayMovie(_masterWin, cString.getBuffer());
-						if (pBmp != nullptr) {
-							pBmp->paint(_masterWin, 0, 0);
-						}
-					}
-					if (shouldQuit())
-						goto exit;
-
-					// Use hi-res movie if user has a fast machine
-					cString = (getMachineSpeed() < 100) ? SMK_LOGO3EX : SMK_LOGO3;
-					MACROREPLACE(cString);
-
-					if (fileExists(cString.getBuffer())) {
-						bofPlayMovie(_masterWin, cString.getBuffer());
-						if (pBmp != nullptr) {
-							pBmp->paint(_masterWin, 0, 0);
-						}
+				cString = SMK_LOGO2;
+				MACROREPLACE(cString);
+				if (fileExists(cString.getBuffer())) {
+					bofPlayMovie(_masterWin, cString.getBuffer());
+					if (pBmp != nullptr) {
+						pBmp->paint(_masterWin, 0, 0);
 					}
 				}
 				if (shouldQuit())
 					goto exit;
 
-				// Start a new game (In entry vestibule)
-				_masterWin->newGame();
+				// Use hi-res movie if user has a fast machine
+				cString = (getMachineSpeed() < 100) ? SMK_LOGO3EX : SMK_LOGO3;
+				MACROREPLACE(cString);
+
+				if (fileExists(cString.getBuffer())) {
+					bofPlayMovie(_masterWin, cString.getBuffer());
+					if (pBmp != nullptr) {
+						pBmp->paint(_masterWin, 0, 0);
+					}
+				}
 			}
+			if (shouldQuit())
+				goto exit;
 
-		} else {
-			reportError(ERR_MEMORY, "Unable to allocate the main SpaceBar Window");
+			// Start a new game (In entry vestibule)
+			_masterWin->newGame();
 		}
 	}
 




More information about the Scummvm-git-logs mailing list