[Scummvm-git-logs] scummvm master -> ad6dab7bfddc900895b8ac23cf55c7071d15d5a1

ccawley2011 noreply at scummvm.org
Fri Feb 3 22:18:49 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
ad6dab7bfd TINYGL: Fix memory leak


Commit: ad6dab7bfddc900895b8ac23cf55c7071d15d5a1
    https://github.com/scummvm/scummvm/commit/ad6dab7bfddc900895b8ac23cf55c7071d15d5a1
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2023-02-03T22:18:45Z

Commit Message:
TINYGL: Fix memory leak

Changed paths:
    engines/freescape/gfx_tinygl_texture.cpp
    engines/freescape/gfx_tinygl_texture.h
    graphics/tinygl/init.cpp
    graphics/tinygl/texture.cpp
    graphics/tinygl/zgl.h


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);




More information about the Scummvm-git-logs mailing list