From 35367e28126f3980fd1f0f54b829791009fe1b30 Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Tue, 24 Sep 2024 14:22:26 +0200 Subject: [PATCH] fix crashes when changing resolution Thanks @JNechaevsky --- src/i_video.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/i_video.c b/src/i_video.c index f4f81e7f2..e4cdc0414 100644 --- a/src/i_video.c +++ b/src/i_video.c @@ -1906,19 +1906,23 @@ void I_ReInitGraphics (int reinit) #ifndef CRISPY_TRUECOLOR SDL_FreeSurface(screenbuffer); - screenbuffer = SDL_CreateRGBSurface(0, - SCREENWIDTH, SCREENHEIGHT, 8, - 0, 0, 0, 0); -#endif + screenbuffer = SDL_CreateRGBSurface( + 0, SCREENWIDTH, SCREENHEIGHT, 8, + 0, 0, 0, 0); + // pixels and pitch will be filled with the texture's values + // in I_FinishUpdate() SDL_FreeSurface(argbbuffer); - argbbuffer = SDL_CreateRGBSurfaceWithFormat(0, - SCREENWIDTH, SCREENHEIGHT, 32, - SDL_PIXELFORMAT_ARGB8888); -#ifndef CRISPY_TRUECOLOR + argbbuffer = SDL_CreateRGBSurfaceWithFormatFrom( + NULL, SCREENWIDTH, SCREENHEIGHT, 0, 0, SDL_PIXELFORMAT_ARGB8888); + // [crispy] re-set the framebuffer pointer I_VideoBuffer = screenbuffer->pixels; #else + SDL_FreeSurface(argbbuffer); + argbbuffer = SDL_CreateRGBSurfaceWithFormat( + 0, SCREENWIDTH, SCREENHEIGHT, 32, SDL_PIXELFORMAT_ARGB8888); + I_VideoBuffer = argbbuffer->pixels; #endif V_RestoreBuffer();