comparison 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
comparison
equal deleted inserted replaced
1592:31effaadf877 1593:24508cb54f87
539 un_textures[1] = glGetUniformLocation(program, "textures[1]"); 539 un_textures[1] = glGetUniformLocation(program, "textures[1]");
540 un_width = glGetUniformLocation(program, "width"); 540 un_width = glGetUniformLocation(program, "width");
541 un_height = glGetUniformLocation(program, "height"); 541 un_height = glGetUniformLocation(program, "height");
542 at_pos = glGetAttribLocation(program, "pos"); 542 at_pos = glGetAttribLocation(program, "pos");
543 } 543 }
544
545 static void gl_teardown()
546 {
547 glDeleteProgram(program);
548 glDeleteShader(vshader);
549 glDeleteShader(fshader);
550 glDeleteBuffers(2, buffers);
551 glDeleteTextures(3, textures);
552 }
544 #endif 553 #endif
545 554
546 static uint8_t texture_init; 555 static uint8_t texture_init;
547 static void render_alloc_surfaces() 556 static void render_alloc_surfaces()
548 { 557 {
586 595
587 static void render_quit() 596 static void render_quit()
588 { 597 {
589 render_close_audio(); 598 render_close_audio();
590 free_surfaces(); 599 free_surfaces();
600 #ifndef DISABLE_OPENGL
601 if (render_gl) {
602 gl_teardown();
603 SDL_GL_DeleteContext(main_context);
604 }
605 #endif
591 } 606 }
592 607
593 static float config_aspect() 608 static float config_aspect()
594 { 609 {
595 static float aspect = 0.0f; 610 static float aspect = 0.0f;
864 #ifndef DISABLE_OPENGL 879 #ifndef DISABLE_OPENGL
865 if (render_gl) { 880 if (render_gl) {
866 if (on_context_destroyed) { 881 if (on_context_destroyed) {
867 on_context_destroyed(); 882 on_context_destroyed();
868 } 883 }
884 gl_teardown();
869 SDL_GL_DeleteContext(main_context); 885 SDL_GL_DeleteContext(main_context);
870 main_context = SDL_GL_CreateContext(main_window); 886 main_context = SDL_GL_CreateContext(main_window);
871 gl_setup(); 887 gl_setup();
872 if (on_context_created) { 888 if (on_context_created) {
873 on_context_created(); 889 on_context_created();
1146 #ifndef DISABLE_OPENGL 1162 #ifndef DISABLE_OPENGL
1147 if (render_gl) { 1163 if (render_gl) {
1148 if (on_context_destroyed) { 1164 if (on_context_destroyed) {
1149 on_context_destroyed(); 1165 on_context_destroyed();
1150 } 1166 }
1167 gl_teardown();
1151 SDL_GL_DeleteContext(main_context); 1168 SDL_GL_DeleteContext(main_context);
1152 } else { 1169 } else {
1153 #endif 1170 #endif
1154 SDL_DestroyRenderer(main_renderer); 1171 SDL_DestroyRenderer(main_renderer);
1155 #ifndef DISABLE_OPENGL 1172 #ifndef DISABLE_OPENGL