From fc5a357caabb4dc4b09edb0981cd5af6eeb7a57d Mon Sep 17 00:00:00 2001 From: tobid7 Date: Sat, 5 Sep 2026 18:06:12 +0200 Subject: [PATCH] stop leaking idobj memory (and coloredit layout mem) --- include/pd/ui7/container/coloredit.hpp | 150 +++++++++++++------------ include/pd/ui7/layout.hpp | 2 +- source/ui7/layout.cpp | 10 ++ 3 files changed, 87 insertions(+), 75 deletions(-) diff --git a/include/pd/ui7/container/coloredit.hpp b/include/pd/ui7/container/coloredit.hpp index db00652..cab4efe 100755 --- a/include/pd/ui7/container/coloredit.hpp +++ b/include/pd/ui7/container/coloredit.hpp @@ -1,75 +1,77 @@ -#pragma once - -/* -MIT License -Copyright (c) 2024 - 2026 René Amthor (tobid7) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - */ - -#include -#include -#include - -namespace PD { -namespace UI7 { -/** - * Color Editor (Creating a PopUP when clicking) - */ -class PD_API ColorEdit : public Container { - public: - /** - * Constructor - * @param label Label of the Button - * @param pos Base Position - * @param lr Reference to the Renderer - */ - ColorEdit(const std::string& label, u32* color, UI7::IO& io) { - // PD::Assert(color != nullptr, "Input Color Address is null!"); - this->label = label; - this->color_ref = color; - this->initial_color = *color; - this->tdim = io.Font->GetTextBounds(label.c_str(), io.FontScale); - } - ~ColorEdit() = default; - - /** - * Override for the Input Handler - * @note This function is usally called by Menu::Update - */ - void HandleInput() override; - /** - * Override for the Rendering Handler - * @note This function is usally called by Menu::Update - * */ - void Draw() override; - - /** Function to Update Size if framepadding changes */ - void Update() override; - - private: - fvec2 tdim; ///< Text size - u32* color_ref = nullptr; ///< Color Reference - u32 initial_color; ///< Initial Color - std::string label; ///< Label of the Button - Layout* layout = nullptr; ///< Layout to open - bool is_shown = false; ///< AHow Layout Editor -}; -} // namespace UI7 +#pragma once + +/* +MIT License +Copyright (c) 2024 - 2026 René Amthor (tobid7) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ + +#include +#include +#include + +namespace PD { +namespace UI7 { +/** + * Color Editor (Creating a PopUP when clicking) + */ +class PD_API ColorEdit : public Container { + public: + /** + * Constructor + * @param label Label of the Button + * @param pos Base Position + * @param lr Reference to the Renderer + */ + ColorEdit(const std::string& label, u32* color, UI7::IO& io) { + // PD::Assert(color != nullptr, "Input Color Address is null!"); + this->label = label; + this->color_ref = color; + this->initial_color = *color; + this->tdim = io.Font->GetTextBounds(label.c_str(), io.FontScale); + } + ~ColorEdit() { + if (layout) delete layout; + } + + /** + * Override for the Input Handler + * @note This function is usally called by Menu::Update + */ + void HandleInput() override; + /** + * Override for the Rendering Handler + * @note This function is usally called by Menu::Update + * */ + void Draw() override; + + /** Function to Update Size if framepadding changes */ + void Update() override; + + private: + fvec2 tdim; ///< Text size + u32* color_ref = nullptr; ///< Color Reference + u32 initial_color; ///< Initial Color + std::string label; ///< Label of the Button + Layout* layout = nullptr; ///< Layout to open + bool is_shown = false; ///< AHow Layout Editor +}; +} // namespace UI7 } // namespace PD \ No newline at end of file diff --git a/include/pd/ui7/layout.hpp b/include/pd/ui7/layout.hpp index 04adfec..79d2945 100644 --- a/include/pd/ui7/layout.hpp +++ b/include/pd/ui7/layout.hpp @@ -47,7 +47,7 @@ class PD_API Layout { Size = 0; WorkRect = fvec4(IO.MenuPadding, Size - (fvec2(2) * IO.MenuPadding)); } - ~Layout() = default; + ~Layout(); /** SECTION CONTAINERS */ /** diff --git a/source/ui7/layout.cpp b/source/ui7/layout.cpp index 6e27a98..22db057 100644 --- a/source/ui7/layout.cpp +++ b/source/ui7/layout.cpp @@ -26,6 +26,15 @@ SOFTWARE. namespace PD { namespace UI7 { + +PD_API Layout::~Layout() { + // We all love managing memory i guess + for (Container* obj : IDObjects) { + delete obj; + } + IDObjects.clear(); +} + PD_API void Layout::CursorInit() { Cursor = fvec2(WorkRect.x, WorkRect.y); } PD_API void Layout::SameLine() { @@ -136,6 +145,7 @@ PD_API void Layout::Update() { for (auto it = IDObjects.begin(); it != IDObjects.end();) { if ((*it)->Removable()) { + delete *it; it = IDObjects.erase(it); } else { it++;