aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2010-08-04 12:41:00 +0000
committerFilippos Karapetis2010-08-04 12:41:00 +0000
commit624107319ef8d57854b6b8e4d264831697d5d00e (patch)
treed8322371ea9061e012ad81181b18b912fe11f68a
parent74304fb790759a1dc4dc9b078565b9eba0fe2c34 (diff)
downloadscummvm-rg350-624107319ef8d57854b6b8e4d264831697d5d00e.tar.gz
scummvm-rg350-624107319ef8d57854b6b8e4d264831697d5d00e.tar.bz2
scummvm-rg350-624107319ef8d57854b6b8e4d264831697d5d00e.zip
SCI: Fixed an off-by-one error in GfxPorts::getPortById() and moved the error checking code outside the function. Also fixed script bug #3039305 - "HOYLE4: segfault"
svn-id: r51733
-rw-r--r--engines/sci/graphics/ports.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/engines/sci/graphics/ports.cpp b/engines/sci/graphics/ports.cpp
index afbe0e676c..0c97f5d29b 100644
--- a/engines/sci/graphics/ports.cpp
+++ b/engines/sci/graphics/ports.cpp
@@ -179,8 +179,18 @@ void GfxPorts::kernelSetActive(uint16 portId) {
case 0xFFFF:
setPort(_menuPort);
break;
- default:
- setPort(getPortById(portId));
+ default: {
+ Port *newPort = getPortById(portId);
+ if (newPort)
+ setPort(newPort);
+ else {
+ if (g_sci->getGameId() == GID_HOYLE4 && portId == 3) {
+ // Hoyle 4 attempts to set invalid port ID 3 when closing the options dialog (bug #3039305)
+ } else {
+ error("GfxPorts::kernelSetActive was requested to set invalid port id %d", portId);
+ }
+ }
+ }
};
}
@@ -218,7 +228,10 @@ reg_t GfxPorts::kernelNewWindow(Common::Rect dims, Common::Rect restoreRect, uin
void GfxPorts::kernelDisposeWindow(uint16 windowId, bool reanimate) {
Window *wnd = (Window *)getPortById(windowId);
- removeWindow(wnd, reanimate);
+ if (wnd)
+ removeWindow(wnd, reanimate);
+ else
+ error("GfxPorts::kernelDisposeWindow: Request to dispose invalid port id %d", windowId);
}
int16 GfxPorts::isFrontWindow(Window *pWnd) {
@@ -415,7 +428,7 @@ void GfxPorts::removeWindow(Window *pWnd, bool reanimate) {
_paint16->kernelGraphRedrawBox(pWnd->restoreRect);
_windowList.remove(pWnd);
setPort(_windowList.back());
- _windowsById[pWnd->id] = 0;
+ _windowsById[pWnd->id] = NULL;
delete pWnd;
}
@@ -444,9 +457,7 @@ void GfxPorts::updateWindow(Window *wnd) {
}
Port *GfxPorts::getPortById(uint16 id) {
- if (id > _windowsById.size())
- error("getPortById() received invalid id");
- return _windowsById[id];
+ return (id < _windowsById.size()) ? _windowsById[id] : NULL;
}
Port *GfxPorts::setPort(Port *newPort) {