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.
This commit is contained in:
2024-01-27 14:45:37 +00:00
committed by GitHub
parent 8a4a99b7e8
commit fef0bfcfd3
7 changed files with 20 additions and 4 deletions

View File

@@ -82,13 +82,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);