(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
authorDarkvater
Sat, 18 Nov 2006 00:44:09 +0000
changeset 5121 e45de1152730
parent 5120 1ff65e874ce3
child 5122 3aa375cb5e8e
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
window.c
--- a/window.c	Sat Nov 18 00:14:43 2006 +0000
+++ b/window.c	Sat Nov 18 00:44:09 2006 +0000
@@ -337,12 +337,13 @@
 {
 	Window *w;
 
-	for (w = _windows; w != _last_window;) {
+restart_search:
+	/* When we find the window to delete, we need to restart the search
+	 * as deleting this window could cascade in deleting (many) others */
+	for (w = _windows; w != _last_window; w++) {
 		if (w->window_class == cls) {
 			DeleteWindow(w);
-			w = _windows;
-		} else {
-			w++;
+			goto restart_search;
 		}
 	}
 }
@@ -355,12 +356,13 @@
 {
 	Window *w;
 
-	for (w = _windows; w != _last_window;) {
+restart_search:
+	/* When we find the window to delete, we need to restart the search
+	 * as deleting this window could cascade in deleting (many) others */
+	for (w = _windows; w != _last_window; w++) {
 		if (w->caption_color == id) {
 			DeleteWindow(w);
-			w = _windows;
-		} else {
-			w++;
+			goto restart_search;
 		}
 	}
 
@@ -1756,7 +1758,10 @@
 {
 	Window *w;
 
-	for (w = _windows; w != _last_window;) {
+restart_search:
+	/* When we find the window to delete, we need to restart the search
+	 * as deleting this window could cascade in deleting (many) others */
+	for (w = _windows; w != _last_window; w++) {
 		if (w->window_class != WC_MAIN_WINDOW &&
 				w->window_class != WC_SELECT_GAME &&
 				w->window_class != WC_MAIN_TOOLBAR &&
@@ -1765,9 +1770,7 @@
 				w->window_class != WC_TOOLTIPS &&
 				(w->flags4 & WF_STICKY) == 0) { // do not delete windows which are 'pinned'
 			DeleteWindow(w);
-			w = _windows;
-		} else {
-			w++;
+			goto restart_search;
 		}
 	}
 }
@@ -1781,15 +1784,15 @@
 {
 	Window *w;
 
-	// Delete every window except for stickied ones
+	/* Delete every window except for stickied ones, then sticky ones as well */
 	DeleteNonVitalWindows();
-	// Delete all sticked windows
-	for (w = _windows; w != _last_window;) {
+restart_search:
+	/* When we find the window to delete, we need to restart the search
+	 * as deleting this window could cascade in deleting (many) others */
+	for (w = _windows; w != _last_window; w++) {
 		if (w->flags4 & WF_STICKY) {
 			DeleteWindow(w);
-			w = _windows;
-		} else {
-			w++;
+			goto restart_search;
 		}
 	}
 }