Fix: TextfileWindow called virtual methods before constructor completed. (#11889)

SetStringParameters() was called during widget tree init in the constructor.

Calls within a constructor cannot call the derived classes methods. This would result in invalid data being passed to the string system, which could then crash.

(cherry picked from commit fef0bfcfd3)
This commit is contained in:
Peter Nelson
2024-01-27 14:45:37 +00:00
committed by Jonathan G Rennison
parent a7c2f489f6
commit 4bf9c123d3
8 changed files with 22 additions and 4 deletions

View File

@@ -84,13 +84,19 @@ static WindowDesc _textfile_desc(__FILE__, __LINE__,
);
TextfileWindow::TextfileWindow(TextfileType file_type) : Window(&_textfile_desc), file_type(file_type)
{
/* Init of nested tree is deferred.
* TextfileWindow::ConstructWindow must be called by the inheriting window. */
}
void TextfileWindow::ConstructWindow()
{
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_TF_VSCROLLBAR);
this->hscroll = this->GetScrollbar(WID_TF_HSCROLLBAR);
this->GetWidget<NWidgetCore>(WID_TF_CAPTION)->SetDataTip(STR_TEXTFILE_README_CAPTION + file_type, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
this->GetWidget<NWidgetCore>(WID_TF_CAPTION)->SetDataTip(STR_TEXTFILE_README_CAPTION + this->file_type, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
this->GetWidget<NWidgetStacked>(WID_TF_SEL_JUMPLIST)->SetDisplayedPlane(SZSP_HORIZONTAL);
this->FinishInitNested(file_type);
this->FinishInitNested(this->file_type);
this->DisableWidget(WID_TF_NAVBACK);
this->DisableWidget(WID_TF_NAVFORWARD);