Skip to content

Commit

Permalink
Fix #7089: close NewGRF textfile windows when their data are invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
glx22 committed Jan 26, 2019
1 parent 1334cfb commit 8302ce7
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/newgrf_gui.cpp
Expand Up @@ -725,7 +725,11 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
GRFConfig *d = new GRFConfig(*a);
d->next = (*c)->next;
d->CopyParams(**c);
if (this->active_sel == *c) this->active_sel = NULL;
if (this->active_sel == *c) {
DeleteWindowByClass(WC_GRF_PARAMETERS);
DeleteWindowByClass(WC_TEXTFILE);
this->active_sel = NULL;
}
delete *c;
*c = d;
iter->second = d;
Expand Down Expand Up @@ -1022,7 +1026,10 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
GRFConfig *c;
for (c = this->actives; c != NULL && i > 0; c = c->next, i--) {}

if (this->active_sel != c) DeleteWindowByClass(WC_GRF_PARAMETERS);
if (this->active_sel != c) {
DeleteWindowByClass(WC_GRF_PARAMETERS);
DeleteWindowByClass(WC_TEXTFILE);
}
this->active_sel = c;
this->avail_sel = NULL;
this->avail_pos = -1;
Expand All @@ -1039,6 +1046,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
case WID_NS_REMOVE: { // Remove GRF
if (this->active_sel == NULL || !this->editable) break;
DeleteWindowByClass(WC_GRF_PARAMETERS);
DeleteWindowByClass(WC_TEXTFILE);

/* Choose the next GRF file to be the selected file. */
GRFConfig *newsel = this->active_sel->next;
Expand Down Expand Up @@ -1080,6 +1088,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
this->active_sel = NULL;
DeleteWindowByClass(WC_GRF_PARAMETERS);
if (i < this->avails.Length()) {
if (this->avail_sel != this->avails[i]) DeleteWindowByClass(WC_TEXTFILE);
this->avail_sel = this->avails[i];
this->avail_pos = i;
}
Expand Down Expand Up @@ -1152,11 +1161,11 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {

virtual void OnNewGRFsScanned()
{
if (this->active_sel == NULL) DeleteWindowByClass(WC_TEXTFILE);
this->avail_sel = NULL;
this->avail_pos = -1;
this->avails.ForceRebuild();
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
this->DeleteChildWindows(WC_TEXTFILE); // Remove the view textfile window
}

virtual void OnDropdownSelect(int widget, int index)
Expand All @@ -1173,6 +1182,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {

ResetObjectToPlace();
DeleteWindowByClass(WC_GRF_PARAMETERS);
DeleteWindowByClass(WC_TEXTFILE);
this->active_sel = NULL;
this->InvalidateData(GOID_NEWGRF_PRESET_LOADED);
}
Expand Down Expand Up @@ -1221,7 +1231,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
*l = new GRFConfig(*f);
(*l)->next = c->next;

if (active_sel == c) active_sel = *l;
if (this->active_sel == c) this->active_sel = *l;

delete c;
}
Expand Down Expand Up @@ -1347,6 +1357,9 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {

if (this->avails.Length() == 0) this->avail_pos = -1;
if (this->avail_pos >= 0) {
this->active_sel = NULL;
DeleteWindowByClass(WC_GRF_PARAMETERS);
if (this->avail_sel != this->avails[this->avail_pos]) DeleteWindowByClass(WC_TEXTFILE);
this->avail_sel = this->avails[this->avail_pos];
this->vscroll2->ScrollTowards(this->avail_pos);
this->InvalidateData(0);
Expand Down Expand Up @@ -1509,6 +1522,8 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
{
if (this->avail_sel == NULL || !this->editable || HasBit(this->avail_sel->flags, GCF_INVALID)) return false;

DeleteWindowByClass(WC_TEXTFILE);

uint count = 0;
GRFConfig **entry = NULL;
GRFConfig **list;
Expand Down Expand Up @@ -1968,6 +1983,7 @@ static void NewGRFConfirmationCallback(Window *w, bool confirmed)
{
if (confirmed) {
DeleteWindowByClass(WC_GRF_PARAMETERS);
DeleteWindowByClass(WC_TEXTFILE);
NewGRFWindow *nw = dynamic_cast<NewGRFWindow*>(w);

GamelogStartAction(GLAT_GRF);
Expand Down

0 comments on commit 8302ce7

Please sign in to comment.