TINYGL: Fix memory leak

This commit is contained in:
Cameron Cawley 2023-02-03 16:48:27 +00:00
parent 0af9e4b53b
commit 50d7086d4a
5 changed files with 4 additions and 15 deletions

View file

@ -33,7 +33,6 @@ TinyGLTexture::TinyGLTexture(const Graphics::Surface *surface) {
_width = surface->w; _width = surface->w;
_height = surface->h; _height = surface->h;
_format = surface->format; _format = surface->format;
_id = 0;
_internalFormat = 0; _internalFormat = 0;
_sourceFormat = 0; _sourceFormat = 0;
@ -43,7 +42,6 @@ TinyGLTexture::TinyGLTexture(const Graphics::Surface *surface) {
} }
TinyGLTexture::~TinyGLTexture() { TinyGLTexture::~TinyGLTexture() {
tglDeleteTextures(1, &_id);
tglDeleteBlitImage(_blitImage); tglDeleteBlitImage(_blitImage);
} }

View file

@ -40,7 +40,6 @@ public:
void update(const Graphics::Surface *surface) override; void update(const Graphics::Surface *surface) override;
void updatePartial(const Graphics::Surface *surface, const Common::Rect &rect) override; void updatePartial(const Graphics::Surface *surface, const Common::Rect &rect) override;
TGLuint _id;
TGLuint _internalFormat; TGLuint _internalFormat;
TGLuint _sourceFormat; TGLuint _sourceFormat;

View file

@ -37,15 +37,11 @@ void GLContext::initSharedState() {
GLSharedState *s = &shared_state; GLSharedState *s = &shared_state;
s->lists = (GLList **)gl_zalloc(sizeof(GLList *) * MAX_DISPLAY_LISTS); s->lists = (GLList **)gl_zalloc(sizeof(GLList *) * MAX_DISPLAY_LISTS);
s->texture_hash_table = (GLTexture **)gl_zalloc(sizeof(GLTexture *) * TEXTURE_HASH_TABLE_SIZE); s->texture_hash_table = (GLTexture **)gl_zalloc(sizeof(GLTexture *) * TEXTURE_HASH_TABLE_SIZE);
alloc_texture(0);
} }
void GLContext::endSharedState() { void GLContext::endSharedState() {
GLSharedState *s = &shared_state; GLSharedState *s = &shared_state;
uint h = 0;
free_texture(h);
for (int i = 0; i < MAX_DISPLAY_LISTS; i++) { for (int i = 0; i < MAX_DISPLAY_LISTS; i++) {
// TODO // TODO
} }
@ -146,7 +142,7 @@ void GLContext::init(int screenW, int screenH, Graphics::PixelFormat pixelFormat
// textures // textures
texture_2d_enabled = false; texture_2d_enabled = false;
current_texture = alloc_texture(0); current_texture = default_texture = alloc_texture(0);
maxTextureName = 0; maxTextureName = 0;
texture_mag_filter = TGL_LINEAR; texture_mag_filter = TGL_LINEAR;
texture_min_filter = TGL_NEAREST_MIPMAP_LINEAR; texture_min_filter = TGL_NEAREST_MIPMAP_LINEAR;
@ -291,6 +287,7 @@ void GLContext::deinit() {
specbuf_cleanup(); specbuf_cleanup();
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
gl_free(matrix_stack[i]); gl_free(matrix_stack[i]);
free_texture(default_texture);
endSharedState(); endSharedState();
gl_free(vertex); gl_free(vertex);
delete fb; delete fb;

View file

@ -45,10 +45,6 @@ GLTexture *GLContext::find_texture(uint h) {
return nullptr; return nullptr;
} }
void GLContext::free_texture(uint h) {
free_texture(find_texture(h));
}
void GLContext::free_texture(GLTexture *t) { void GLContext::free_texture(GLTexture *t) {
GLTexture **ht; GLTexture **ht;
GLImage *im; GLImage *im;
@ -281,7 +277,7 @@ void GLContext::gl_DeleteTextures(TGLsizei n, const TGLuint *textures) {
TinyGL::GLTexture *t = find_texture(textures[i]); TinyGL::GLTexture *t = find_texture(textures[i]);
if (t) { if (t) {
if (t == current_texture) { if (t == current_texture) {
current_texture = find_texture(0); current_texture = default_texture;
} }
t->disposed = true; t->disposed = true;
} }

View file

@ -294,7 +294,7 @@ struct GLContext {
int current_color_material_type; int current_color_material_type;
// textures // textures
GLTexture *current_texture; GLTexture *current_texture, *default_texture;
uint maxTextureName; uint maxTextureName;
bool texture_2d_enabled; bool texture_2d_enabled;
int texture_mag_filter; int texture_mag_filter;
@ -477,7 +477,6 @@ public:
GLTexture *alloc_texture(uint h); GLTexture *alloc_texture(uint h);
GLTexture *find_texture(uint h); GLTexture *find_texture(uint h);
void free_texture(uint h);
void free_texture(GLTexture *t); void free_texture(GLTexture *t);
void gl_GenTextures(TGLsizei n, TGLuint *textures); void gl_GenTextures(TGLsizei n, TGLuint *textures);
void gl_DeleteTextures(TGLsizei n, const TGLuint *textures); void gl_DeleteTextures(TGLsizei n, const TGLuint *textures);