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.
This commit is contained in:
Tamás Bálint Misius 2021-10-27 21:20:58 +02:00
parent 0f2eedd4fb
commit f07879d165
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
2 changed files with 7 additions and 9 deletions

View File

@ -24,19 +24,19 @@ public:
ui::Colour highColour, lowColour; ui::Colour highColour, lowColour;
ui::Button *highColourButton, *lowColourButton; ui::Button *highColourButton, *lowColourButton;
ui::Textbox *nameField, *ruleField; ui::Textbox *nameField, *ruleField;
GOLTool * tool; GameModel * gameModel;
Simulation *sim; Simulation *sim;
int toolSelection; 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 Validate();
void OnDraw() override; void OnDraw() override;
void OnTryExit(ExitMethod method) override; void OnTryExit(ExitMethod method) override;
virtual ~GOLWindow() {} 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)), ui::Window(ui::Point(-1, -1), ui::Point(200, 108)),
tool(tool_), gameModel(gameModel_),
sim(sim_), sim(sim_),
toolSelection(toolSelection) toolSelection(toolSelection)
{ {
@ -131,7 +131,6 @@ void GOLWindow::UpdateGradient()
void GOLWindow::Validate() void GOLWindow::Validate()
{ {
tool->selectGOLType.clear();
auto nameString = nameField->GetText(); auto nameString = nameField->GetText();
auto ruleString = ruleField->GetText(); auto ruleString = ruleField->GetText();
if (!ValidateGOLName(nameString)) if (!ValidateGOLName(nameString))
@ -164,8 +163,8 @@ void GOLWindow::Validate()
return; return;
} }
tool->gameModel->SelectNextIdentifier = "DEFAULT_PT_LIFECUST_" + nameString.ToAscii(); gameModel->SelectNextIdentifier = "DEFAULT_PT_LIFECUST_" + nameString.ToAscii();
tool->gameModel->SelectNextTool = toolSelection; gameModel->SelectNextTool = toolSelection;
} }
void GOLWindow::OnTryExit(ExitMethod method) 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) 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);
} }

View File

@ -107,7 +107,6 @@ public:
class GOLTool: public Tool class GOLTool: public Tool
{ {
public: public:
String selectGOLType;
GameModel * gameModel; GameModel * gameModel;
GOLTool(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), Tool(0, "CUST", "Add a new custom GOL type. (Use ctrl+shift+rightclick to remove them)", 0xfe, 0xa9, 0x00, "DEFAULT_UI_ADDLIFE", NULL),