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

@ -76,7 +76,7 @@ class DrawComponent {
std::weak_ptr<CollabListType::ObjectInfo> collabListInfo;
std::weak_ptr<DrawingProgramCacheBVHNode> parentBvhNode;
ServerClientID id;
ServerClientID id = {0, 0};
#ifndef IS_SERVER
std::chrono::time_point<std::chrono::steady_clock> lastUpdateTime;

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 {

View file

@ -97,14 +97,6 @@ void MainProgram::update() {
deltaTime.update_time_since();
deltaTime.update_time_point();
toolbar.update();
if(input.key(InputManager::KEY_NOGUI).pressed)
drawGui = !drawGui;
if(input.key(InputManager::KEY_FULLSCREEN).pressed)
input.toggleFullscreen = true;
for(auto& w : worlds) {
if(w == world)
@ -113,6 +105,14 @@ void MainProgram::update() {
w->unfocus_update();
}
toolbar.update(); // GUI should be setup after the world data has been fully updated for this frame, so that the GUI reflects the current state of the world data
if(input.key(InputManager::KEY_NOGUI).pressed)
drawGui = !drawGui;
if(input.key(InputManager::KEY_FULLSCREEN).pressed)
input.toggleFullscreen = true;
NetLibrary::update();
if(tabSetToOpen) {

View file

@ -85,7 +85,7 @@ class World {
void undo_with_checks();
void redo_with_checks();
ServerPortionID ownID;
ServerPortionID ownID = 0;
std::filesystem::path filePath;
Vector3f userColor = {0.0f, 0.0f, 0.0f};
@ -95,8 +95,8 @@ class World {
void set_canvas_background_color(const Vector3f& newBackColor, bool sendChangeOverNetwork = true);
struct CanvasTheme {
SkColor4f backColor;
SkColor4f toolFrontColor;
SkColor4f backColor = {0.0f, 0.0f, 0.0f, 1.0f};
SkColor4f toolFrontColor = {1.0f, 1.0f, 1.0f, 1.0f};
} canvasTheme;
void scale_up(const WorldScalar& scaleUpAmount);