commit d2b0ae8770bdf99f981eba35e30713150093a093
Author: Willem Jan Palenstijn <wjp@usecode.org>
Date:   Mon Feb 28 20:32:46 2011 +0100

    SCI: Skip Ports when iterating over Windows in GC

diff --git a/engines/sci/engine/gc.cpp b/engines/sci/engine/gc.cpp
index e080ad6..b5290c9 100644
--- a/engines/sci/engine/gc.cpp
+++ b/engines/sci/engine/gc.cpp
@@ -86,14 +86,13 @@ static void processWorkList(SegManager *segMan, WorklistManager &wm, const Commo
 }
 
 static void processEngineHunkList(WorklistManager &wm) {
-	PortList windowList = g_sci->_gfxPorts->_windowList;
-
-	for (PortList::const_iterator it = windowList.begin(); it != windowList.end(); ++it) {
-		// FIXME: We also store Port objects in the window list.
-		// We should add a check that we really only pass windows here...
-		Window *wnd = ((Window *)*it);
-		wm.push(wnd->hSaved1);
-		wm.push(wnd->hSaved2);
+	for (uint16 id = 0; id <= g_sci->_gfxPorts->getMaxPortId(); ++id) {
+		Port *p = g_sci->_gfxPorts->getPortById(id);
+		if (p->isWindow()) {
+			Window *wnd = (Window *)p;
+			wm.push(wnd->hSaved1);
+			wm.push(wnd->hSaved2);
+		}
 	}
 }
 
diff --git a/engines/sci/graphics/helpers.h b/engines/sci/graphics/helpers.h
index f6cb214..3c6515a 100644
--- a/engines/sci/graphics/helpers.h
+++ b/engines/sci/graphics/helpers.h
@@ -45,6 +45,10 @@ typedef int GuiResourceId; // is a resource-number and -1 means no parameter giv
 
 typedef int16 TextAlignment;
 
+#define PORTS_FIRSTWINDOWID 2
+#define PORTS_FIRSTSCRIPTWINDOWID 3
+
+
 struct Port {
 	uint16 id;
 	int16 top, left;
@@ -62,6 +66,8 @@ struct Port {
 		fontHeight(0), fontId(0), greyedOutput(false),
 		penClr(0), backClr(0xFF), penMode(0), counterTillFree(0) {
 	}
+
+	bool isWindow() const { return id >= PORTS_FIRSTWINDOWID && id != 0xFFFF; }
 };
 
 struct Window : public Port, public Common::Serializable {
diff --git a/engines/sci/graphics/ports.cpp b/engines/sci/graphics/ports.cpp
index b19a862..7ee674b 100644
--- a/engines/sci/graphics/ports.cpp
+++ b/engines/sci/graphics/ports.cpp
@@ -248,6 +248,8 @@ void GfxPorts::beginUpdate(Window *wnd) {
 	while (it != end) {
 		// FIXME: We also store Port objects in the window list.
 		// We should add a check that we really only pass windows here...
+		assert((*it)->isWindow());
+
 		updateWindow((Window *)*it);
 		--it;
 	}
@@ -265,6 +267,8 @@ void GfxPorts::endUpdate(Window *wnd) {
 	while (++it != end) {
 		// FIXME: We also store Port objects in the window list.
 		// We should add a check that we really only pass windows here...
+		assert((*it)->isWindow());
+
 		updateWindow((Window *)*it);
 	}
 
@@ -490,6 +494,10 @@ Port *GfxPorts::getPortById(uint16 id) {
 	return (id < _windowsById.size()) ? _windowsById[id] : NULL;
 }
 
+uint16 GfxPorts::getMaxPortId() const {
+	return _windowsById.empty() ? 0 : _windowsById.size()-1;
+}
+
 Port *GfxPorts::setPort(Port *newPort) {
 	Port *oldPort = _curPort;
 	_curPort = newPort;
diff --git a/engines/sci/graphics/ports.h b/engines/sci/graphics/ports.h
index b94d54a..34e1648 100644
--- a/engines/sci/graphics/ports.h
+++ b/engines/sci/graphics/ports.h
@@ -37,9 +37,6 @@ class GfxPaint16;
 class GfxScreen;
 class GfxText16;
 
-#define PORTS_FIRSTWINDOWID 2
-#define PORTS_FIRSTSCRIPTWINDOWID 3
-
 // window styles
 enum {
 	SCI_WINDOWMGR_STYLE_TRANSPARENT = (1 << 0),
@@ -81,6 +78,7 @@ public:
 	void updateWindow(Window *wnd);
 
 	Port *getPortById(uint16 id);
+	uint16 getMaxPortId() const;
 
 	Port *setPort(Port *newPort);
 	Port *getPort();
@@ -118,10 +116,10 @@ public:
 
 	virtual void saveLoadWithSerializer(Common::Serializer &ser);
 
+private:
 	/** The list of open 'windows' (and ports), in visual order. */
 	PortList _windowList;
 
-private:
 	/** The list of all open 'windows' (and ports), ordered by their id. */
 	PortArray _windowsById;
 
