summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-10-31 14:53:19 +0000
committerrubidium <rubidium@openttd.org>2009-10-31 14:53:19 +0000
commit86fd0c0bcefd51d4e173ea1287d0b447b2410bfe (patch)
tree6e31997d3f43852034efb2a56e3e43379c1bf69e
parent617e7966f9efd260c02fa252aa106200eddefc7c (diff)
downloadopenttd-86fd0c0bcefd51d4e173ea1287d0b447b2410bfe.tar.xz
(svn r17922) -Fix [FS#3291]: crash when closing NewGRF parameter window with no NewGRF selected
-rw-r--r--src/newgrf_gui.cpp3
-rw-r--r--src/window.cpp15
-rw-r--r--src/window_gui.h2
3 files changed, 13 insertions, 7 deletions
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index c9ac27f3c..5319b1c3f 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -749,6 +749,7 @@ struct NewGRFWindow : public Window {
this->sel = newsel;
this->preset = -1;
this->InvalidateData();
+ this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
break;
}
@@ -791,6 +792,8 @@ struct NewGRFWindow : public Window {
uint i = (pt.y - this->GetWidget<NWidgetBase>(SNGRFS_FILE_LIST)->pos_y) / this->resize.step_height + this->vscroll.GetPosition();
for (c = this->list; c != NULL && i > 0; c = c->next, i--) {}
+
+ if (this->sel != c) this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
this->sel = c;
this->InvalidateData();
diff --git a/src/window.cpp b/src/window.cpp
index 4c1b8d698..ff5ac700f 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -645,12 +645,14 @@ void Window::ReInit()
/** Find the Window whose parent pointer points to this window
* @param w parent Window to find child of
- * @return a Window pointer that is the child of w, or NULL otherwise */
-static Window *FindChildWindow(const Window *w)
+ * @param wc Window class of the window to remove; WC_INVALID if class does not matter
+ * @return a Window pointer that is the child of w, or NULL otherwise
+ */
+static Window *FindChildWindow(const Window *w, WindowClass wc)
{
Window *v;
FOR_ALL_WINDOWS_FROM_BACK(v) {
- if (v->parent == w) return v;
+ if ((wc == WC_INVALID || wc == v->window_class) && v->parent == w) return v;
}
return NULL;
@@ -658,13 +660,14 @@ static Window *FindChildWindow(const Window *w)
/**
* Delete all children a window might have in a head-recursive manner
+ * @param wc Window class of the window to remove; WC_INVALID if class does not matter
*/
-void Window::DeleteChildWindows() const
+void Window::DeleteChildWindows(WindowClass wc) const
{
- Window *child = FindChildWindow(this);
+ Window *child = FindChildWindow(this, wc);
while (child != NULL) {
delete child;
- child = FindChildWindow(this);
+ child = FindChildWindow(this, wc);
}
}
diff --git a/src/window_gui.h b/src/window_gui.h
index c31f7ae62..4e574ec48 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -621,7 +621,7 @@ public:
void DrawViewport() const;
void DrawSortButtonState(int widget, SortButtonState state) const;
- void DeleteChildWindows() const;
+ void DeleteChildWindows(WindowClass wc = WC_INVALID) const;
void SetDirty() const;
void ReInit();