diff render_sdl.c @ 1593:24508cb54f87

Fix a number of other memory errors (mostly leaks again) identified by valgrind
author Michael Pavone <pavone@retrodev.com>
date Thu, 28 Jun 2018 09:27:05 -0700
parents 5cfc7e4a207e
children 437e80a700aa
line wrap: on
line diff
--- a/render_sdl.c	Fri Jun 22 23:10:27 2018 -0700
+++ b/render_sdl.c	Thu Jun 28 09:27:05 2018 -0700
@@ -541,6 +541,15 @@
 	un_height = glGetUniformLocation(program, "height");
 	at_pos = glGetAttribLocation(program, "pos");
 }
+
+static void gl_teardown()
+{
+	glDeleteProgram(program);
+	glDeleteShader(vshader);
+	glDeleteShader(fshader);
+	glDeleteBuffers(2, buffers);
+	glDeleteTextures(3, textures);
+}
 #endif
 
 static uint8_t texture_init;
@@ -588,6 +597,12 @@
 {
 	render_close_audio();
 	free_surfaces();
+#ifndef DISABLE_OPENGL
+	if (render_gl) {
+		gl_teardown();
+		SDL_GL_DeleteContext(main_context);
+	}
+#endif
 }
 
 static float config_aspect()
@@ -866,6 +881,7 @@
 				if (on_context_destroyed) {
 					on_context_destroyed();
 				}
+				gl_teardown();
 				SDL_GL_DeleteContext(main_context);
 				main_context = SDL_GL_CreateContext(main_window);
 				gl_setup();
@@ -1148,6 +1164,7 @@
 		if (on_context_destroyed) {
 			on_context_destroyed();
 		}
+		gl_teardown();
 		SDL_GL_DeleteContext(main_context);
 	} else {
 #endif