Skip to content

Commit 3c2a19e

Browse files
committed
Fix: Fix memory leak in HUD::Item using a dtor
1 parent 4fef97d commit 3c2a19e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/flamegpu/visualiser/HUD.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ HUD::Item::Item(std::shared_ptr<Overlay> overlay, const glm::ivec2 &offset, cons
153153
GL_CALL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, 4*sizeof(int), &faces, GL_STATIC_DRAW));
154154
GL_CALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
155155
}
156+
HUD::Item::~Item() {
157+
if (data) {
158+
free(data);
159+
data = nullptr;
160+
}
161+
}
156162
void HUD::Item::resizeWindow(const glm::uvec2 &dims) {
157163
// Track parameters, so when called from overlay we can reuse previous
158164
static glm::uvec2 _dims;

src/flamegpu/visualiser/HUD.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class HUD {
5050
* @param zIndex The priority for which overlay should be on-top.
5151
*/
5252
Item(std::shared_ptr<Overlay> overlay, const glm::ivec2 &offset, const glm::uvec2 &windowDims, AnchorV anchorV = AnchorV::Center, AnchorH anchorH = AnchorH::Center, const int &zIndex = 0);
53+
/**
54+
* Destructor to free manually allocated memory
55+
*/
56+
~Item();
5357
/**
5458
* Convenience resizeWindow(const glm::uvec2 &)
5559
* @param w The new window width

0 commit comments

Comments
 (0)