[Scummvm-git-logs] scummvm master -> 43a4f406d10cfe323dbbe7236c4417ab81056a77
Strangerke
noreply at scummvm.org
Tue May 14 19:51:37 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:
43a4f406d1 BAGEL: more work on fatal errors
Commit: 43a4f406d10cfe323dbbe7236c4417ab81056a77
https://github.com/scummvm/scummvm/commit/43a4f406d10cfe323dbbe7236c4417ab81056a77
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-14T20:50:49+01:00
Commit Message:
BAGEL: more work on fatal errors
Changed paths:
engines/bagel/boflib/dat_file.cpp
engines/bagel/boflib/gui/dialog.cpp
engines/bagel/boflib/gui/list_box.cpp
engines/bagel/boflib/gui/scroll_bar.cpp
engines/bagel/boflib/gui/text_box.cpp
engines/bagel/boflib/gui/window.cpp
diff --git a/engines/bagel/boflib/dat_file.cpp b/engines/bagel/boflib/dat_file.cpp
index 0da7d531fa5..fa423edc38f 100644
--- a/engines/bagel/boflib/dat_file.cpp
+++ b/engines/bagel/boflib/dat_file.cpp
@@ -93,7 +93,9 @@ ErrorCode CBofDataFile::setFile(const char *pszFileName, uint32 lFlags, const ch
if (!(_lFlags & CDF_KEEPOPEN)) {
close();
}
- }
+ } else
+ reportError(ERR_FOPEN, "Could not open file %s", _szFileName);
+
} else {
reportError(ERR_FFIND, "Could not build full path to %s", pszFileName);
}
diff --git a/engines/bagel/boflib/gui/dialog.cpp b/engines/bagel/boflib/gui/dialog.cpp
index 65503d944db..6e2c9850510 100644
--- a/engines/bagel/boflib/gui/dialog.cpp
+++ b/engines/bagel/boflib/gui/dialog.cpp
@@ -107,14 +107,13 @@ ErrorCode CBofDialog::create(const char *pszName, CBofRect *pRect, CBofWindow *p
assert(isValidObject(this));
assert(pszName != nullptr);
- CBofRect cRect;
int x = 0;
int y = 0;
int nWidth = USE_DEFAULT;
int nHeight = USE_DEFAULT;
if ((pRect == nullptr) && (_pBackdrop != nullptr)) {
- cRect = _pBackdrop->getRect();
+ CBofRect cRect = _pBackdrop->getRect();
pRect = &cRect;
}
@@ -204,13 +203,11 @@ ErrorCode CBofDialog::saveBackground() {
delete _pDlgBackground;
// Save a copy of the background
_pDlgBackground = new CBofBitmap(width(), height(), pPalette);
- if (_pDlgBackground != nullptr) {
- _pDlgBackground->captureScreen(this, &_cRect);
- _pDlgBackground->setReadOnly(true);
+ if (_pDlgBackground == nullptr)
+ fatalError(ERR_MEMORY, "Unable to allocate a new CBofBitmap(%d x %d)", width(), height());
- } else {
- reportError(ERR_MEMORY, "Unable to allocate a new CBofBitmap(%d x %d)", width(), height());
- }
+ _pDlgBackground->captureScreen(this, &_cRect);
+ _pDlgBackground->setReadOnly(true);
}
_bFirstTime = false;
diff --git a/engines/bagel/boflib/gui/list_box.cpp b/engines/bagel/boflib/gui/list_box.cpp
index c8bdf20d1d5..eaeb3941fd4 100644
--- a/engines/bagel/boflib/gui/list_box.cpp
+++ b/engines/bagel/boflib/gui/list_box.cpp
@@ -337,18 +337,14 @@ ErrorCode CBofListBox::saveBackground() {
killBackground();
_pBackdrop = new CBofBitmap(width(), height(), CBofApp::getApp()->getPalette());
- if (_pBackdrop != nullptr) {
- if ((_parent != nullptr) && (_parent->getBackdrop() != nullptr)) {
- CBofRect cRect = _pBackdrop->getRect();
-
- _parent->getBackdrop()->paint(_pBackdrop, &cRect, &_cWindowRect);
-
- } else {
- _pBackdrop->captureScreen(this, &_cRect);
- }
+ if (_pBackdrop == nullptr)
+ fatalError(ERR_MEMORY, "Unable to allocate a %d x %d CBofBitmap", width(), height());
+ if ((_parent != nullptr) && (_parent->getBackdrop() != nullptr)) {
+ CBofRect cRect = _pBackdrop->getRect();
+ _parent->getBackdrop()->paint(_pBackdrop, &cRect, &_cWindowRect);
} else {
- reportError(ERR_MEMORY, "Unable to allocate a %d x %d CBofBitmap", width(), height());
+ _pBackdrop->captureScreen(this, &_cRect);
}
return _errCode;
@@ -365,7 +361,7 @@ ErrorCode CBofListBox::createWorkArea() {
assert(_pBackdrop != nullptr);
_pWork = new CBofBitmap(width(), height(), _pBackdrop->getPalette());
if (_pWork == nullptr) {
- reportError(ERR_MEMORY, "Unable to allocate a %d x %d CBofBitmap", width(), height());
+ fatalError(ERR_MEMORY, "Unable to allocate a %d x %d CBofBitmap", width(), height());
}
}
diff --git a/engines/bagel/boflib/gui/scroll_bar.cpp b/engines/bagel/boflib/gui/scroll_bar.cpp
index 7fc329a0920..ae81177edaa 100644
--- a/engines/bagel/boflib/gui/scroll_bar.cpp
+++ b/engines/bagel/boflib/gui/scroll_bar.cpp
@@ -111,10 +111,8 @@ ErrorCode CBofScrollBar::setText(const char *pszText, int nJustify) {
cTempRect.right += 20;
_pScrollText = new CBofText(&cTempRect, nJustify);
- if (_pScrollText != nullptr) {
-
- } else {
- reportError(ERR_MEMORY, "Could not allocate a new CBofText");
+ if (_pScrollText == nullptr) {
+ fatalError(ERR_MEMORY, "Could not allocate a new CBofText");
}
}
@@ -219,11 +217,12 @@ ErrorCode CBofScrollBar::loadBitmaps(const char *pszBack, const char *pszThumb,
_nScrollWidth = _cBkSize.cx;
_pThumb = new CBofSprite;
- if (_pThumb != nullptr) {
- if (_pThumb->loadSprite(pszThumb) != false) {
- _pThumb->setMaskColor(COLOR_WHITE);
- _cThumbSize = _pThumb->getSize();
- }
+ if (_pThumb == nullptr)
+ fatalError(ERR_MEMORY, "Could not allocate a new CBofSprite");
+
+ if (_pThumb->loadSprite(pszThumb) != false) {
+ _pThumb->setMaskColor(COLOR_WHITE);
+ _cThumbSize = _pThumb->getSize();
}
delete _pLeftBtnUp;
@@ -232,18 +231,16 @@ ErrorCode CBofScrollBar::loadBitmaps(const char *pszBack, const char *pszThumb,
CBofPoint cPoint;
if (pszLeftBtnUp != nullptr) {
_pLeftBtnUp = new CBofBitmap(pszLeftBtnUp, pPalette);
- if (_pLeftBtnUp != nullptr) {
- cPoint.x = 0;
- cPoint.y = (_pBackdrop->height() / 2) - (_pLeftBtnUp->height() / 2);
+ if (_pLeftBtnUp == nullptr)
+ fatalError(ERR_MEMORY, "Could not allocate a new CBofBitmap(%s)", pszLeftBtnUp);
- _cLeftBtnRect = _pLeftBtnUp->getRect() + cPoint;
+ cPoint.x = 0;
+ cPoint.y = (_pBackdrop->height() / 2) - (_pLeftBtnUp->height() / 2);
- _nOffset = _pLeftBtnUp->width();
- _nScrollWidth -= _nOffset;
+ _cLeftBtnRect = _pLeftBtnUp->getRect() + cPoint;
- } else {
- reportError(ERR_MEMORY, "Could not allocate a new CBofBitmap(%s)", pszLeftBtnUp);
- }
+ _nOffset = _pLeftBtnUp->width();
+ _nScrollWidth -= _nOffset;
}
delete _pRightBtnUp;
@@ -251,15 +248,14 @@ ErrorCode CBofScrollBar::loadBitmaps(const char *pszBack, const char *pszThumb,
if (pszRightBtnUp != nullptr) {
_pRightBtnUp = new CBofBitmap(pszRightBtnUp, pPalette);
- if (_pRightBtnUp != nullptr) {
- cPoint.x = _pBackdrop->width() - _pRightBtnUp->width();
- cPoint.y = (_pBackdrop->height() / 2) - (_pRightBtnUp->height() / 2);
- _cRightBtnRect = _pLeftBtnUp->getRect() + cPoint;
-
- _nScrollWidth -= _cRightBtnRect.width();
- } else {
- reportError(ERR_MEMORY, "Could not allocate a new CBofBitmap(%s)", pszRightBtnUp);
- }
+ if (_pRightBtnUp == nullptr)
+ fatalError(ERR_MEMORY, "Could not allocate a new CBofBitmap(%s)", pszRightBtnUp);
+
+ cPoint.x = _pBackdrop->width() - _pRightBtnUp->width();
+ cPoint.y = (_pBackdrop->height() / 2) - (_pRightBtnUp->height() / 2);
+ _cRightBtnRect = _pLeftBtnUp->getRect() + cPoint;
+
+ _nScrollWidth -= _cRightBtnRect.width();
}
delete _pLeftBtnDn;
@@ -268,7 +264,7 @@ ErrorCode CBofScrollBar::loadBitmaps(const char *pszBack, const char *pszThumb,
if (pszLeftBtnDn != nullptr) {
_pLeftBtnDn = new CBofBitmap(pszLeftBtnDn, pPalette);
if (_pLeftBtnDn == nullptr) {
- reportError(ERR_MEMORY, "Could not allocate a new CBofBitmap(%s)", pszLeftBtnDn);
+ fatalError(ERR_MEMORY, "Could not allocate a new CBofBitmap(%s)", pszLeftBtnDn);
}
}
@@ -278,7 +274,7 @@ ErrorCode CBofScrollBar::loadBitmaps(const char *pszBack, const char *pszThumb,
if (pszRightBtnDn != nullptr) {
_pRightBtnDn = new CBofBitmap(pszRightBtnDn, pPalette);
if (_pRightBtnDn == nullptr) {
- reportError(ERR_MEMORY, "Could not allocate a new CBofBitmap(%s)", pszRightBtnDn);
+ fatalError(ERR_MEMORY, "Could not allocate a new CBofBitmap(%s)", pszRightBtnDn);
}
}
@@ -307,44 +303,43 @@ ErrorCode CBofScrollBar::paint(CBofRect *pDirtyRect) {
if ((_pBackdrop != nullptr) && (_pThumb != nullptr)) {
// Do all painting offscreen
CBofBitmap *pBmp = new CBofBitmap(_cBkSize.cx, _cBkSize.cy, pPalette);
- if (pBmp != nullptr) {
- _pBackdrop->paint(pBmp, 0, 0, nullptr, COLOR_WHITE);
+ if (pBmp == nullptr)
+ fatalError(ERR_MEMORY, "Could not allocate a new CBofBitmap(%d x %d))", _cBkSize.cx, _cBkSize.cy);
+
+ _pBackdrop->paint(pBmp, 0, 0, nullptr, COLOR_WHITE);
- if ((_nScrollState == 1) && (_pLeftBtnDn != nullptr)) {
- cPoint = _cLeftBtnRect.topLeft();
- _pLeftBtnDn->paint(pBmp, cPoint.x, cPoint.y, nullptr, COLOR_WHITE);
+ if ((_nScrollState == 1) && (_pLeftBtnDn != nullptr)) {
+ cPoint = _cLeftBtnRect.topLeft();
+ _pLeftBtnDn->paint(pBmp, cPoint.x, cPoint.y, nullptr, COLOR_WHITE);
- } else if (_pLeftBtnUp != nullptr) {
- cPoint = _cLeftBtnRect.topLeft();
- _pLeftBtnUp->paint(pBmp, cPoint.x, cPoint.y, nullptr, COLOR_WHITE);
- }
+ } else if (_pLeftBtnUp != nullptr) {
+ cPoint = _cLeftBtnRect.topLeft();
+ _pLeftBtnUp->paint(pBmp, cPoint.x, cPoint.y, nullptr, COLOR_WHITE);
+ }
- if ((_nScrollState == 4) && (_pRightBtnDn != nullptr)) {
- cPoint = _cRightBtnRect.topLeft();
- _pRightBtnDn->paint(pBmp, cPoint.x, cPoint.y, nullptr, COLOR_WHITE);
+ if ((_nScrollState == 4) && (_pRightBtnDn != nullptr)) {
+ cPoint = _cRightBtnRect.topLeft();
+ _pRightBtnDn->paint(pBmp, cPoint.x, cPoint.y, nullptr, COLOR_WHITE);
- } else if (_pRightBtnUp != nullptr) {
- cPoint = _cRightBtnRect.topLeft();
- _pRightBtnUp->paint(pBmp, cPoint.x, cPoint.y, nullptr, COLOR_WHITE);
- }
+ } else if (_pRightBtnUp != nullptr) {
+ cPoint = _cRightBtnRect.topLeft();
+ _pRightBtnUp->paint(pBmp, cPoint.x, cPoint.y, nullptr, COLOR_WHITE);
+ }
- _cThumbPos.x = (int)(((int32)(_nScrollWidth - _cThumbSize.cx) * _nPos) / (_nRange - 1)) + _nOffset;
- _cThumbPos.y = (int)(_cBkSize.cy / 2) - (int)(_cThumbSize.cy / 2);
+ _cThumbPos.x = (int)(((int32)(_nScrollWidth - _cThumbSize.cx) * _nPos) / (_nRange - 1)) + _nOffset;
+ _cThumbPos.y = (int)(_cBkSize.cy / 2) - (int)(_cThumbSize.cy / 2);
- if (_cThumbPos.x < 0)
- _cThumbPos.x = 0;
- if (_cThumbPos.x > (_nScrollWidth - _cThumbSize.cx + _nOffset))
- _cThumbPos.x = _nScrollWidth - _cThumbSize.cx + _nOffset;
+ if (_cThumbPos.x < 0)
+ _cThumbPos.x = 0;
+ if (_cThumbPos.x > (_nScrollWidth - _cThumbSize.cx + _nOffset))
+ _cThumbPos.x = _nScrollWidth - _cThumbSize.cx + _nOffset;
- _pThumb->paintSprite(pBmp, _cThumbPos);
+ _pThumb->paintSprite(pBmp, _cThumbPos);
- // now we can paint the offscreen buffer to the screen
- pBmp->paint(this, 0, 0);
+ // now we can paint the offscreen buffer to the screen
+ pBmp->paint(this, 0, 0);
- delete pBmp;
- } else {
- reportError(ERR_MEMORY, "Could not allocate a new CBofBitmap(%d x %d))", _cBkSize.cx, _cBkSize.cy);
- }
+ delete pBmp;
}
if ((_pScrollText != nullptr) && (_parent != nullptr)) {
diff --git a/engines/bagel/boflib/gui/text_box.cpp b/engines/bagel/boflib/gui/text_box.cpp
index 92580df00a2..9de54edf245 100644
--- a/engines/bagel/boflib/gui/text_box.cpp
+++ b/engines/bagel/boflib/gui/text_box.cpp
@@ -111,9 +111,8 @@ ErrorCode CBofTextBox::setBox(const CBofRect *pRect) {
// Create a new text field the size of the box we want
_pTextField = new CBofText(pRect, JUSTIFY_WRAP);
- if (_pTextField == nullptr) {
- reportError(ERR_MEMORY, "Could not allocate a CBofText");
- }
+ if (_pTextField == nullptr)
+ fatalError(ERR_MEMORY, "Could not allocate a CBofText");
return _errCode;
}
diff --git a/engines/bagel/boflib/gui/window.cpp b/engines/bagel/boflib/gui/window.cpp
index 593e6ef4233..7d562988258 100644
--- a/engines/bagel/boflib/gui/window.cpp
+++ b/engines/bagel/boflib/gui/window.cpp
@@ -78,7 +78,7 @@ CBofWindow::~CBofWindow() {
killBackdrop();
- destroy();
+ CBofWindow::destroy();
}
ErrorCode CBofWindow::initialize() {
@@ -100,10 +100,8 @@ Common::Point CBofWindow::getMousePos() {
void CBofWindow::destroy() {
releaseCapture();
- if (_surface != nullptr) {
- delete _surface;
- _surface = nullptr;
- }
+ delete _surface;
+ _surface = nullptr;
// When gui elements are destroyed, remove them
// from the _children array of their parent
@@ -113,10 +111,8 @@ void CBofWindow::destroy() {
void CBofWindow::validateAnscestors(CBofRect *pRect) {
assert(isValidObject(this));
- CBofWindow *pParent;
-
// Validate all anscestors
- pParent = _parent;
+ CBofWindow *pParent = _parent;
while (pParent != nullptr) {
pParent->validateRect(pRect);
pParent = pParent->getParent();
@@ -150,8 +146,8 @@ ErrorCode CBofWindow::create(const char *pszName, int x, int y, int nWidth, int
_surface = new Graphics::ManagedSurface(*g_engine->_screen, stRect);
if (!errorOccurred()) {
- CBofPalette *pPalette;
- if ((pPalette = CBofApp::getApp()->getPalette()) != nullptr) {
+ CBofPalette *pPalette = CBofApp::getApp()->getPalette();
+ if (pPalette != nullptr) {
selectPalette(pPalette);
}
@@ -186,10 +182,11 @@ ErrorCode CBofWindow::create(const char *pszName, const CBofRect *pRect, CBofWin
assert(isValidObject(this));
assert(pszName != nullptr);
- int x, y, nWidth, nHeight;
+ int x = 0;
+ int y = 0;
- x = y = 0;
- nWidth = nHeight = USE_DEFAULT;
+ int nWidth = USE_DEFAULT;
+ int nHeight = USE_DEFAULT;
if (pRect != nullptr) {
x = pRect->left;
@@ -231,13 +228,11 @@ bool CBofWindow::hasFocus() const {
void CBofWindow::center() {
assert(isValidObject(this));
- CBofWindow *pParent;
+ CBofWindow *pParent = _parent;
int x, y;
- if ((pParent = _parent) != nullptr) {
- CBofRect cWindowRect;
-
- cWindowRect = pParent->getWindowRect();
+ if (pParent != nullptr) {
+ CBofRect cWindowRect = pParent->getWindowRect();
x = cWindowRect.left + (pParent->width() - width()) / 2;
y = cWindowRect.top + (pParent->height() - height()) / 2;
@@ -321,20 +316,22 @@ void CBofWindow::setTimer(uint32 nID, uint32 nInterval, BofCallback pCallBack) {
pPacket = (CBofTimerPacket *)pPacket->getNext();
}
- if ((pPacket = new CBofTimerPacket) != nullptr) {
- pPacket->_nID = nID;
- pPacket->_nInterval = nInterval;
- pPacket->_pCallBack = pCallBack;
- pPacket->_pOwnerWindow = this;
+ pPacket = new CBofTimerPacket;
+ if (pPacket == nullptr)
+ fatalError(ERR_MEMORY, "Unable to allocate a CBofTimerPacket");
- // Add this timer to the list of current timers
- if (_pTimerList != nullptr) {
- _pTimerList->addToHead(pPacket);
- }
+ pPacket->_nID = nID;
+ pPacket->_nInterval = nInterval;
+ pPacket->_pCallBack = pCallBack;
+ pPacket->_pOwnerWindow = this;
- _pTimerList = pPacket;
+ // Add this timer to the list of current timers
+ if (_pTimerList != nullptr) {
+ _pTimerList->addToHead(pPacket);
}
+ _pTimerList = pPacket;
+
// Add the timer to the window
_timers.push_back(WindowTimer(nInterval, nID, pCallBack));
}
@@ -370,11 +367,9 @@ void CBofWindow::killTimer(uint32 nID) {
void CBofWindow::killMyTimers() {
assert(isValidObject(this));
- CBofTimerPacket *pTimer, *pNextTimer;
-
- pTimer = _pTimerList;
+ CBofTimerPacket *pTimer = _pTimerList;
while (pTimer != nullptr) {
- pNextTimer = (CBofTimerPacket *)pTimer->getNext();
+ CBofTimerPacket *pNextTimer = (CBofTimerPacket *)pTimer->getNext();
if (pTimer->_pOwnerWindow == this) {
killTimer(pTimer->_nID);
@@ -385,14 +380,12 @@ void CBofWindow::killMyTimers() {
}
void CBofWindow::checkTimers() {
- uint32 currTime;
-
for (uint i = 0; i < _children.size(); ++i)
_children[i]->checkTimers();
for (bool timersChanged = true; timersChanged;) {
timersChanged = false;
- currTime = g_system->getMillis();
+ uint32 currTime = g_system->getMillis();
// Iterate over the timers looking for any that have expired
for (Common::List<WindowTimer>::iterator it = _timers.begin(); it != _timers.end(); ++it) {
@@ -493,29 +486,20 @@ ErrorCode CBofWindow::setBackdrop(const char *pszFileName, bool bRefresh) {
assert(isValidObject(this));
assert(pszFileName != nullptr);
- CBofBitmap *pBmp;
- CBofPalette *pPalette;
-
// Use Application's palette if none supplied
- pPalette = CBofApp::getApp()->getPalette();
-
- if ((pBmp = new CBofBitmap(pszFileName, pPalette)) != nullptr) {
- return setBackdrop(pBmp, bRefresh);
-
- } else {
- reportError(ERR_MEMORY, "Could not allocate a new CBofBitmap");
- }
+ CBofPalette *pPalette = CBofApp::getApp()->getPalette();
+ CBofBitmap *pBmp = new CBofBitmap(pszFileName, pPalette);
+ if (pBmp == nullptr)
+ fatalError(ERR_MEMORY, "Could not allocate a new CBofBitmap");
- return _errCode;
+ return setBackdrop(pBmp, bRefresh);
}
void CBofWindow::killBackdrop() {
assert(isValidObject(this));
- if (_pBackdrop != nullptr) {
- delete _pBackdrop;
- _pBackdrop = nullptr;
- }
+ delete _pBackdrop;
+ _pBackdrop = nullptr;
}
ErrorCode CBofWindow::paintBackdrop(CBofRect *pRect, int nTransparentColor) {
@@ -524,7 +508,6 @@ ErrorCode CBofWindow::paintBackdrop(CBofRect *pRect, int nTransparentColor) {
if (_pBackdrop != nullptr) {
if (pRect == nullptr) {
_errCode = _pBackdrop->paint(this, &_cRect, nullptr, nTransparentColor);
-
} else {
_errCode = _pBackdrop->paint(this, pRect, pRect, nTransparentColor);
}
More information about the Scummvm-git-logs
mailing list