(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
authordarkvater
Thu, 13 Jan 2005 16:50:20 +0000
changeset 999 8b2a34061963
parent 998 d9dc257b8949
child 1000 a418026097f6
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
-Added DeleteWindowByClass() function that deletes all windows of a given class
functions.h
main_gui.c
window.c
--- a/functions.h	Thu Jan 13 16:28:47 2005 +0000
+++ b/functions.h	Thu Jan 13 16:50:20 2005 +0000
@@ -201,6 +201,7 @@
 void InvalidateWindowWidget(byte cls, WindowNumber number, byte widget_index);
 void InvalidateWindowClasses(byte cls);
 void DeleteWindowById(WindowClass cls, WindowNumber number);
+void DeleteWindowByClass(WindowClass cls);
 
 void SetObjectToPlaceWnd(int icon, byte mode, Window *w);
 void SetObjectToPlace(int icon, byte mode, WindowClass window_class, WindowNumber window_num);
--- a/main_gui.c	Thu Jan 13 16:28:47 2005 +0000
+++ b/main_gui.c	Thu Jan 13 16:50:20 2005 +0000
@@ -1097,10 +1097,13 @@
 			break;
 		case 4:
 			DeleteWindow(w);
-			if(mode) { // reset landscape
+			DeleteWindowByClass(WC_INDUSTRY_VIEW);
+			DeleteWindowByClass(WC_TOWN_VIEW);
+			DeleteWindowByClass(WC_LAND_INFO);			
+
+			if (mode) { // reset landscape
 				ResetLandscape();
-			}
-			else { // make random landscape
+			} else { // make random landscape
 				SndPlayFx(SND_15_BEEP);
 				_switch_mode = SM_GENRANDLAND;
 			}
--- a/window.c	Thu Jan 13 16:28:47 2005 +0000
+++ b/window.c	Thu Jan 13 16:50:20 2005 +0000
@@ -262,6 +262,18 @@
 	DeleteWindow(FindWindowById(cls, number));
 }
 
+void DeleteWindowByClass(WindowClass cls)
+{
+	Window *w;
+	for (w = _windows; w != _last_window;) {
+		if (w->window_class == cls) {
+			DeleteWindow(w);
+			w = _windows;
+		} else
+			w++;
+	}
+}
+
 Window *BringWindowToFrontById(WindowClass cls, WindowNumber number)
 {
 	Window *w = FindWindowById(cls, number);