From 38d9385eff4ea0edef250a3ee7068614f22c9c88 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Mon, 7 Jan 2019 16:20:39 +0100 Subject: [PATCH] fixed potential crash bug (accessing already destroyed SDL renderer) This bug was caused by destroying textures after reinitializing the window, which causes the SDL renderer to be destroyed and created for the new window. Unfortunately, to destroy the old textures (which were created using the previous renderer), the old renderer is used, causing access to already free()'d memory. To fix this bug, all textures are destroyed before the renderer is destroyed (and re-created). This bug caused regular crashes of the Windows version of the game when switching between level sets that redefine the window size (while no such crashes were observed with the Linux or Mac version). --- src/tools.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tools.c b/src/tools.c index 6763d611..459f85a7 100644 --- a/src/tools.c +++ b/src/tools.c @@ -9658,6 +9658,8 @@ void ChangeViewportPropertiesIfNeeded(void) { // printf("::: init_video_buffer\n"); + FreeAllImageTextures(); // needs old renderer to free the textures + InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen); InitImageTextures(); } -- 2.34.1