Fixed some memory leaks and uses of uninitialized values

This commit is contained in:
Yousef Khadadeh 2025-10-11 15:35:17 +03:00
parent 48156cb4bf
commit 0cc326bcc9
12 changed files with 28 additions and 21 deletions

View file

@ -359,6 +359,11 @@ void DrawingProgram::update() {
selection.update();
drawTool->tool_update();
if(toolToSwitchToAfterUpdate) {
switch_to_tool_ptr(std::move(toolToSwitchToAfterUpdate));
toolToSwitchToAfterUpdate = nullptr;
}
if(controls.leftClickReleased)
controls.leftClickReleased = false;

View file

@ -93,6 +93,8 @@ class DrawingProgram {
DrawingProgramSelection selection;
std::unique_ptr<DrawingProgramToolBase> toolToSwitchToAfterUpdate;
bool temporaryEraser = false;
bool temporaryPan = false;
DrawingProgramToolType toolTypeAfterTempPan;

View file

@ -40,10 +40,10 @@ bool EllipseDrawEditTool::edit_gui(const std::shared_ptr<DrawComponent>& comp) {
});
}
t.gui.pop_id();
bool editHappened = a->d != oldData;
bool editHappened = (!oldData.has_value()) || (a->d != oldData);
oldData = a->d;
return editHappened;
return editHappened;
}
void EllipseDrawEditTool::edit_start(EditTool& editTool, const std::shared_ptr<DrawComponent>& comp, std::any& prevData) {

View file

@ -16,5 +16,5 @@ class EllipseDrawEditTool : public DrawingProgramEditToolBase {
private:
void commit();
DrawEllipse::Data oldData;
std::optional<DrawEllipse::Data> oldData;
};

View file

@ -39,7 +39,7 @@ bool RectDrawEditTool::edit_gui(const std::shared_ptr<DrawComponent>& comp) {
}
t.gui.pop_id();
bool editHappened = a->d != oldData;
bool editHappened = (!oldData.has_value()) || (a->d != oldData);
oldData = a->d;
return editHappened;
}

View file

@ -14,5 +14,5 @@ class RectDrawEditTool : public DrawingProgramEditToolBase {
virtual bool edit_update(const std::shared_ptr<DrawComponent>& comp) override;
virtual bool edit_gui(const std::shared_ptr<DrawComponent>& comp) override;
private:
DrawRectangle::Data oldData;
std::optional<DrawRectangle::Data> oldData;
};

View file

@ -26,7 +26,7 @@ bool TextBoxEditTool::edit_gui(const std::shared_ptr<DrawComponent>& comp) {
t.gui.text_label("Text Color");
});
t.gui.pop_id();
bool editHappened = a->d != oldData;
bool editHappened = (!oldData.has_value()) || (a->d != oldData);
oldData = a->d;
return editHappened;
}

View file

@ -18,5 +18,5 @@ class TextBoxEditTool : public DrawingProgramEditToolBase {
void edit_text(std::function<void()> toRun, const std::shared_ptr<DrawTextBox>& textBox);
void update_textbox_network(const std::shared_ptr<DrawTextBox>& textBox);
DrawTextBox::Data oldData;
std::optional<DrawTextBox::Data> oldData;
};

View file

@ -67,7 +67,7 @@ void TextBoxTool::tool_update() {
if(!drawP.controls.leftClickHeld) {
auto editTool = std::make_unique<EditTool>(drawP);
editTool->edit_start(controls.intermediateItem);
drawP.switch_to_tool_ptr(std::move(editTool));
drawP.toolToSwitchToAfterUpdate = std::move(editTool);
return;
}
else {