Skip to content

Commit

Permalink
fix HackerPoet#11 (memory leak)
Browse files Browse the repository at this point in the history
  • Loading branch information
hatrd committed May 18, 2023
1 parent 73a9cc7 commit a0b331c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions NonEuclidean/FrameBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ FrameBuffer::FrameBuffer() {
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}

FrameBuffer::~FrameBuffer()
{
glDeleteRenderbuffersEXT(1, &renderBuf);
glDeleteFramebuffersEXT(1, &fbo);
glDeleteTextures(1, &texId);
}

void FrameBuffer::Use() {
glBindTexture(GL_TEXTURE_2D, texId);
}
Expand Down
2 changes: 1 addition & 1 deletion NonEuclidean/FrameBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Portal;
class FrameBuffer {
public:
FrameBuffer();

~FrameBuffer();
void Render(const Camera& cam, GLuint curFBO, const Portal* skipPortal);
void Use();

Expand Down
5 changes: 5 additions & 0 deletions NonEuclidean/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ Texture::Texture(const char* fname, int rows, int cols) {
delete[] img;
}

Texture::~Texture()
{
glDeleteTextures(1, &texId);
}

void Texture::Use() {
if (is3D) {
glBindTexture(GL_TEXTURE_2D_ARRAY, texId);
Expand Down
2 changes: 1 addition & 1 deletion NonEuclidean/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Texture {
public:
Texture(const char* fname, int rows, int cols);

~Texture();
void Use();

private:
Expand Down

0 comments on commit a0b331c

Please sign in to comment.