From 372dc5cca207d29bfb3a33db7936f20be610021d Mon Sep 17 00:00:00 2001 From: louist103 <35883445+louist103@users.noreply.github.com> Date: Sun, 7 Apr 2024 13:50:19 -0400 Subject: [PATCH 1/2] Fix memory leak. --- soh/soh/UIWidgets.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/soh/soh/UIWidgets.cpp b/soh/soh/UIWidgets.cpp index 4817e85fc00..6d95ae4bdca 100644 --- a/soh/soh/UIWidgets.cpp +++ b/soh/soh/UIWidgets.cpp @@ -28,7 +28,7 @@ namespace UIWidgets { std::string newText(text); const size_t tipLength = newText.length(); int lastSpace = -1; - int currentLineLength = 0; + unsigned int currentLineLength = 0; for (unsigned int currentCharacter = 0; currentCharacter < tipLength; currentCharacter++) { if (newText[currentCharacter] == '\n') { currentLineLength = 0; @@ -46,7 +46,7 @@ namespace UIWidgets { currentLineLength++; } - return strdup(newText.c_str()); + return _strdup(newText.c_str()); } char* WrappedText(const std::string& text, unsigned int charactersPerLine) { @@ -56,7 +56,9 @@ namespace UIWidgets { void SetLastItemHoverText(const std::string& text) { if (ImGui::IsItemHovered()) { ImGui::BeginTooltip(); - ImGui::Text("%s", WrappedText(text, 60)); + char* hoverTextWrapped = WrappedText(text, 60); + ImGui::Text("%s", hoverTextWrapped); + free(hoverTextWrapped); ImGui::EndTooltip(); } } @@ -64,7 +66,9 @@ namespace UIWidgets { void SetLastItemHoverText(const char* text) { if (ImGui::IsItemHovered()) { ImGui::BeginTooltip(); - ImGui::Text("%s", WrappedText(text, 60)); + char* hoverTextWrapped = WrappedText(text, 60); + ImGui::Text("%s", hoverTextWrapped); + free(hoverTextWrapped); ImGui::EndTooltip(); } } @@ -75,7 +79,9 @@ namespace UIWidgets { ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "?"); if (ImGui::IsItemHovered()) { ImGui::BeginTooltip(); - ImGui::Text("%s", WrappedText(text, 60)); + char* hoverTextWrapped = WrappedText(text, 60); + ImGui::Text("%s", hoverTextWrapped); + free(hoverTextWrapped); ImGui::EndTooltip(); } } @@ -85,7 +91,9 @@ namespace UIWidgets { ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "?"); if (ImGui::IsItemHovered()) { ImGui::BeginTooltip(); - ImGui::Text("%s", WrappedText(text, 60)); + char* hoverTextWrapped = WrappedText(text, 60); + ImGui::Text("%s", hoverTextWrapped); + free(hoverTextWrapped); ImGui::EndTooltip(); } } @@ -95,7 +103,9 @@ namespace UIWidgets { void Tooltip(const char* text) { if (ImGui::IsItemHovered()) { - ImGui::SetTooltip("%s", WrappedText(text)); + char* tooltipWrapped = WrappedText(text); + ImGui::SetTooltip("%s", tooltipWrapped); + free(tooltipWrapped); } } From 5f11afce5ef9e16522f738f738b92036dcfb9a27 Mon Sep 17 00:00:00 2001 From: louist103 <35883445+louist103@users.noreply.github.com> Date: Sun, 7 Apr 2024 14:28:21 -0400 Subject: [PATCH 2/2] Linux doesn't like the ISO stuff --- soh/soh/UIWidgets.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/soh/soh/UIWidgets.cpp b/soh/soh/UIWidgets.cpp index 6d95ae4bdca..93ad1f1efac 100644 --- a/soh/soh/UIWidgets.cpp +++ b/soh/soh/UIWidgets.cpp @@ -17,6 +17,10 @@ #include #include "soh/Enhancements/cosmetics/CosmeticsEditor.h" +#ifdef _MSC_VER +#define strdup _strdup +#endif + namespace UIWidgets { // MARK: - Layout Helper @@ -46,7 +50,7 @@ namespace UIWidgets { currentLineLength++; } - return _strdup(newText.c_str()); + return strdup(newText.c_str()); } char* WrappedText(const std::string& text, unsigned int charactersPerLine) {