changeset 2388:a8c069d847a0

Fix issue that would break debug windows when config update causes window to be recreated
author Michael Pavone <pavone@retrodev.com>
date Wed, 22 Nov 2023 23:07:30 -0800
parents ff2f18dac84b
children 66b3f2eda0c8
files render_sdl.c
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/render_sdl.c	Wed Nov 22 22:59:57 2023 -0800
+++ b/render_sdl.c	Wed Nov 22 23:07:30 2023 -0800
@@ -476,8 +476,10 @@
 	if (texture_init) {
 		return;
 	}
-	sdl_textures= calloc(sizeof(SDL_Texture *), 3);
-	num_textures = 3;
+	if (!sdl_textures) {
+		sdl_textures= calloc(sizeof(SDL_Texture *), 3);
+		num_textures = 3;
+	}
 	texture_init = 1;
 #ifndef DISABLE_OPENGL
 	if (render_gl) {
@@ -1273,7 +1275,15 @@
 
 void render_config_updated(void)
 {
-	free_surfaces();
+	int n = num_textures < FRAMEBUFFER_USER_START ? num_textures : FRAMEBUFFER_USER_START;
+	for (int i = 0; i < n; i++)
+	{
+		if (sdl_textures[i]) {
+			SDL_DestroyTexture(sdl_textures[i]);
+			sdl_textures[i] = NULL;
+		}
+	}
+	texture_init = 0;
 #ifndef DISABLE_OPENGL
 	if (render_gl) {
 		if (on_context_destroyed) {