mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-21 08:55:04 -05:00
Fix some memory leaks with WrappedText and LoadArrayByNameAsVec3s (#4144)
* avoid memory leaks with WrappedText * avoid memory leak with LoadArrayByNameAsVec3s
This commit is contained in:
parent
cbeec006ec
commit
3f67fed073
@ -782,7 +782,7 @@ void DrawFlagTableArray16(const FlagTable& flagTable, uint16_t row, uint16_t& fl
|
||||
ImGui::PopStyleColor();
|
||||
if (ImGui::IsItemHovered() && hasDescription) {
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("%s", UIWidgets::WrappedText(flagTable.flagDescriptions.at(row * 16 + flagIndex), 60));
|
||||
ImGui::Text("%s", UIWidgets::WrappedText(flagTable.flagDescriptions.at(row * 16 + flagIndex), 60).c_str());
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
ImGui::PopID();
|
||||
|
@ -1735,6 +1735,7 @@ extern "C" char* ResourceMgr_LoadArrayByName(const char* path)
|
||||
return (char*)res->Scalars.data();
|
||||
}
|
||||
|
||||
// Return of LoadArrayByNameAsVec3s must be freed by the caller
|
||||
extern "C" char* ResourceMgr_LoadArrayByNameAsVec3s(const char* path) {
|
||||
auto res = std::static_pointer_cast<LUS::Array>(GetResourceByNameHandlingMQ(path));
|
||||
|
||||
|
@ -21,7 +21,7 @@ namespace UIWidgets {
|
||||
// Automatically adds newlines to break up text longer than a specified number of characters
|
||||
// Manually included newlines will still be respected and reset the line length
|
||||
// If line is midword when it hits the limit, text should break at the last encountered space
|
||||
char* WrappedText(const char* text, unsigned int charactersPerLine) {
|
||||
std::string WrappedText(const char* text, unsigned int charactersPerLine) {
|
||||
std::string newText(text);
|
||||
const size_t tipLength = newText.length();
|
||||
int lastSpace = -1;
|
||||
@ -43,17 +43,17 @@ namespace UIWidgets {
|
||||
currentLineLength++;
|
||||
}
|
||||
|
||||
return strdup(newText.c_str());
|
||||
return newText;
|
||||
}
|
||||
|
||||
char* WrappedText(const std::string& text, unsigned int charactersPerLine) {
|
||||
std::string WrappedText(const std::string& text, unsigned int charactersPerLine) {
|
||||
return WrappedText(text.c_str(), charactersPerLine);
|
||||
}
|
||||
|
||||
void SetLastItemHoverText(const std::string& text) {
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("%s", WrappedText(text, 60));
|
||||
ImGui::Text("%s", WrappedText(text, 60).c_str());
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
@ -61,7 +61,7 @@ namespace UIWidgets {
|
||||
void SetLastItemHoverText(const char* text) {
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("%s", WrappedText(text, 60));
|
||||
ImGui::Text("%s", WrappedText(text, 60).c_str());
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
@ -72,7 +72,7 @@ namespace UIWidgets {
|
||||
ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "?");
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("%s", WrappedText(text, 60));
|
||||
ImGui::Text("%s", WrappedText(text, 60).c_str());
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
@ -82,7 +82,7 @@ namespace UIWidgets {
|
||||
ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "?");
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("%s", WrappedText(text, 60));
|
||||
ImGui::Text("%s", WrappedText(text, 60).c_str());
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
@ -92,7 +92,7 @@ namespace UIWidgets {
|
||||
|
||||
void Tooltip(const char* text) {
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip("%s", WrappedText(text));
|
||||
ImGui::SetTooltip("%s", WrappedText(text).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,8 +50,8 @@ namespace UIWidgets {
|
||||
constexpr float sliderButtonWidth = 30.0f;
|
||||
#endif
|
||||
|
||||
char* WrappedText(const char* text, unsigned int charactersPerLine = 60);
|
||||
char* WrappedText(const std::string& text, unsigned int charactersPerLine);
|
||||
std::string WrappedText(const char* text, unsigned int charactersPerLine = 60);
|
||||
std::string WrappedText(const std::string& text, unsigned int charactersPerLine);
|
||||
|
||||
void SetLastItemHoverText(const std::string& text);
|
||||
void SetLastItemHoverText(const char* text);
|
||||
|
@ -2307,10 +2307,12 @@ void Player_DrawPause(PlayState* play, u8* segment, SkelAnime* skelAnime, Vec3f*
|
||||
}
|
||||
|
||||
srcTable = ResourceMgr_LoadArrayByNameAsVec3s(srcTable);
|
||||
Vec3s* ogSrcTable = srcTable;
|
||||
destTable = skelAnime->jointTable;
|
||||
for (i = 0; i < skelAnime->limbCount; i++) {
|
||||
*destTable++ = *srcTable++;
|
||||
}
|
||||
free(ogSrcTable);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user