From ad6dab7bfddc900895b8ac23cf55c7071d15d5a1 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Fri, 3 Feb 2023 16:48:27 +0000 Subject: [PATCH] TINYGL: Fix memory leak --- engines/freescape/gfx_tinygl_texture.cpp | 2 -- engines/freescape/gfx_tinygl_texture.h | 1 - graphics/tinygl/init.cpp | 7 ++----- graphics/tinygl/texture.cpp | 6 +----- graphics/tinygl/zgl.h | 3 +-- 5 files changed, 4 insertions(+), 15 deletions(-) diff --git a/engines/freescape/gfx_tinygl_texture.cpp b/engines/freescape/gfx_tinygl_texture.cpp index f843d34d5a6..887a386afb7 100644 --- a/engines/freescape/gfx_tinygl_texture.cpp +++ b/engines/freescape/gfx_tinygl_texture.cpp @@ -33,7 +33,6 @@ TinyGLTexture::TinyGLTexture(const Graphics::Surface *surface) { _width = surface->w; _height = surface->h; _format = surface->format; - _id = 0; _internalFormat = 0; _sourceFormat = 0; @@ -43,7 +42,6 @@ TinyGLTexture::TinyGLTexture(const Graphics::Surface *surface) { } TinyGLTexture::~TinyGLTexture() { - tglDeleteTextures(1, &_id); tglDeleteBlitImage(_blitImage); } diff --git a/engines/freescape/gfx_tinygl_texture.h b/engines/freescape/gfx_tinygl_texture.h index cb87a3552bc..5dbedf40f8d 100644 --- a/engines/freescape/gfx_tinygl_texture.h +++ b/engines/freescape/gfx_tinygl_texture.h @@ -40,7 +40,6 @@ public: void update(const Graphics::Surface *surface) override; void updatePartial(const Graphics::Surface *surface, const Common::Rect &rect) override; - TGLuint _id; TGLuint _internalFormat; TGLuint _sourceFormat; diff --git a/graphics/tinygl/init.cpp b/graphics/tinygl/init.cpp index f6a5c05a870..dafcb8f5156 100644 --- a/graphics/tinygl/init.cpp +++ b/graphics/tinygl/init.cpp @@ -37,15 +37,11 @@ void GLContext::initSharedState() { GLSharedState *s = &shared_state; s->lists = (GLList **)gl_zalloc(sizeof(GLList *) * MAX_DISPLAY_LISTS); s->texture_hash_table = (GLTexture **)gl_zalloc(sizeof(GLTexture *) * TEXTURE_HASH_TABLE_SIZE); - - alloc_texture(0); } void GLContext::endSharedState() { GLSharedState *s = &shared_state; - uint h = 0; - free_texture(h); for (int i = 0; i < MAX_DISPLAY_LISTS; i++) { // TODO } @@ -146,7 +142,7 @@ void GLContext::init(int screenW, int screenH, Graphics::PixelFormat pixelFormat // textures texture_2d_enabled = false; - current_texture = alloc_texture(0); + current_texture = default_texture = alloc_texture(0); maxTextureName = 0; texture_mag_filter = TGL_LINEAR; texture_min_filter = TGL_NEAREST_MIPMAP_LINEAR; @@ -291,6 +287,7 @@ void GLContext::deinit() { specbuf_cleanup(); for (int i = 0; i < 3; i++) gl_free(matrix_stack[i]); + free_texture(default_texture); endSharedState(); gl_free(vertex); delete fb; diff --git a/graphics/tinygl/texture.cpp b/graphics/tinygl/texture.cpp index 1b421648bf0..11a93e434b3 100644 --- a/graphics/tinygl/texture.cpp +++ b/graphics/tinygl/texture.cpp @@ -45,10 +45,6 @@ GLTexture *GLContext::find_texture(uint h) { return nullptr; } -void GLContext::free_texture(uint h) { - free_texture(find_texture(h)); -} - void GLContext::free_texture(GLTexture *t) { GLTexture **ht; GLImage *im; @@ -269,7 +265,7 @@ void GLContext::gl_DeleteTextures(TGLsizei n, const TGLuint *textures) { TinyGL::GLTexture *t = find_texture(textures[i]); if (t) { if (t == current_texture) { - current_texture = find_texture(0); + current_texture = default_texture; } t->disposed = true; } diff --git a/graphics/tinygl/zgl.h b/graphics/tinygl/zgl.h index 27013a70e4d..055e4d8a46d 100644 --- a/graphics/tinygl/zgl.h +++ b/graphics/tinygl/zgl.h @@ -294,7 +294,7 @@ struct GLContext { int current_color_material_type; // textures - GLTexture *current_texture; + GLTexture *current_texture, *default_texture; uint maxTextureName; bool texture_2d_enabled; int texture_mag_filter; @@ -477,7 +477,6 @@ public: GLTexture *alloc_texture(uint h); GLTexture *find_texture(uint h); - void free_texture(uint h); void free_texture(GLTexture *t); void gl_GenTextures(TGLsizei n, TGLuint *textures); void gl_DeleteTextures(TGLsizei n, const TGLuint *textures);