(svn r17922) -Fix [FS#3291]: crash when closing NewGRF parameter window with no NewGRF selected

This commit is contained in:
rubidium 2009-10-31 14:53:19 +00:00
parent 9059383676
commit 8742314bb8
3 changed files with 13 additions and 7 deletions

View File

@ -749,6 +749,7 @@ struct NewGRFWindow : public Window {
this->sel = newsel; this->sel = newsel;
this->preset = -1; this->preset = -1;
this->InvalidateData(); this->InvalidateData();
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
break; 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(); 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--) {} 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->sel = c;
this->InvalidateData(); this->InvalidateData();

View File

@ -645,12 +645,14 @@ void Window::ReInit()
/** Find the Window whose parent pointer points to this window /** Find the Window whose parent pointer points to this window
* @param w parent Window to find child of * @param w parent Window to find child of
* @return a Window pointer that is the child of w, or NULL otherwise */ * @param wc Window class of the window to remove; WC_INVALID if class does not matter
static Window *FindChildWindow(const Window *w) * @return a Window pointer that is the child of w, or NULL otherwise
*/
static Window *FindChildWindow(const Window *w, WindowClass wc)
{ {
Window *v; Window *v;
FOR_ALL_WINDOWS_FROM_BACK(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; return NULL;
@ -658,13 +660,14 @@ static Window *FindChildWindow(const Window *w)
/** /**
* Delete all children a window might have in a head-recursive manner * 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) { while (child != NULL) {
delete child; delete child;
child = FindChildWindow(this); child = FindChildWindow(this, wc);
} }
} }

View File

@ -621,7 +621,7 @@ public:
void DrawViewport() const; void DrawViewport() const;
void DrawSortButtonState(int widget, SortButtonState state) const; void DrawSortButtonState(int widget, SortButtonState state) const;
void DeleteChildWindows() const; void DeleteChildWindows(WindowClass wc = WC_INVALID) const;
void SetDirty() const; void SetDirty() const;
void ReInit(); void ReInit();