fixed potential crash bug (accessing already destroyed SDL renderer)
authorHolger Schemel <info@artsoft.org>
Mon, 7 Jan 2019 15:20:39 +0000 (16:20 +0100)
committerHolger Schemel <info@artsoft.org>
Mon, 7 Jan 2019 15:37:48 +0000 (16:37 +0100)
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

index 6763d611a6d9ac384dc0228337f934afe45fcc39..459f85a769cf82263a4229a219130bcc973461af 100644 (file)
@@ -9658,6 +9658,8 @@ void ChangeViewportPropertiesIfNeeded(void)
   {
     // printf("::: init_video_buffer\n");
 
   {
     // printf("::: init_video_buffer\n");
 
+    FreeAllImageTextures();    // needs old renderer to free the textures
+
     InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen);
     InitImageTextures();
   }
     InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen);
     InitImageTextures();
   }