From f07879d16527f5441fddf84bb686bff3188f0769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Wed, 27 Oct 2021 21:20:58 +0200 Subject: [PATCH] Fix potential crash when adding a custom GOL type GOLWindow would try to access a GOLTool that would have been deleted earlier when the menus were rebuilt. --- src/gui/game/GOLTool.cpp | 15 +++++++-------- src/gui/game/Tool.h | 1 - 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/gui/game/GOLTool.cpp b/src/gui/game/GOLTool.cpp index 861bbac53..211bfc8d1 100644 --- a/src/gui/game/GOLTool.cpp +++ b/src/gui/game/GOLTool.cpp @@ -24,19 +24,19 @@ public: ui::Colour highColour, lowColour; ui::Button *highColourButton, *lowColourButton; ui::Textbox *nameField, *ruleField; - GOLTool * tool; + GameModel * gameModel; Simulation *sim; int toolSelection; - GOLWindow(GOLTool *tool_, Simulation *sim, int toolSelection, int rule, int colour1, int colour2); + GOLWindow(GameModel *gameModel, Simulation *sim, int toolSelection, int rule, int colour1, int colour2); void Validate(); void OnDraw() override; void OnTryExit(ExitMethod method) override; virtual ~GOLWindow() {} }; -GOLWindow::GOLWindow(GOLTool * tool_, Simulation *sim_, int toolSelection, int rule, int colour1, int colour2): +GOLWindow::GOLWindow(GameModel * gameModel_, Simulation *sim_, int toolSelection, int rule, int colour1, int colour2): ui::Window(ui::Point(-1, -1), ui::Point(200, 108)), -tool(tool_), +gameModel(gameModel_), sim(sim_), toolSelection(toolSelection) { @@ -131,7 +131,6 @@ void GOLWindow::UpdateGradient() void GOLWindow::Validate() { - tool->selectGOLType.clear(); auto nameString = nameField->GetText(); auto ruleString = ruleField->GetText(); if (!ValidateGOLName(nameString)) @@ -164,8 +163,8 @@ void GOLWindow::Validate() return; } - tool->gameModel->SelectNextIdentifier = "DEFAULT_PT_LIFECUST_" + nameString.ToAscii(); - tool->gameModel->SelectNextTool = toolSelection; + gameModel->SelectNextIdentifier = "DEFAULT_PT_LIFECUST_" + nameString.ToAscii(); + gameModel->SelectNextTool = toolSelection; } void GOLWindow::OnTryExit(ExitMethod method) @@ -197,5 +196,5 @@ void GOLWindow::OnDraw() void GOLTool::OpenWindow(Simulation *sim, int toolSelection, int rule, int colour1, int colour2) { - new GOLWindow(this, sim, toolSelection, rule, colour1, colour2); + new GOLWindow(gameModel, sim, toolSelection, rule, colour1, colour2); } diff --git a/src/gui/game/Tool.h b/src/gui/game/Tool.h index c74883083..0464e44a0 100644 --- a/src/gui/game/Tool.h +++ b/src/gui/game/Tool.h @@ -107,7 +107,6 @@ public: class GOLTool: public Tool { public: - String selectGOLType; GameModel * gameModel; GOLTool(GameModel * gameModel): Tool(0, "CUST", "Add a new custom GOL type. (Use ctrl+shift+rightclick to remove them)", 0xfe, 0xa9, 0x00, "DEFAULT_UI_ADDLIFE", NULL),