From c4bed2f5969adb878c1d4d30dfa2c0c56f5618c6 Mon Sep 17 00:00:00 2001 From: anth64 Date: Wed, 19 Aug 2026 21:53:18 +0200 Subject: [PATCH] refactor(video/sdl): dedupe scale computation and use calloc for framebuffer --- src/platform/client/video/sdl.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/platform/client/video/sdl.c b/src/platform/client/video/sdl.c index af1be49..282fcf8 100644 --- a/src/platform/client/video/sdl.c +++ b/src/platform/client/video/sdl.c @@ -82,7 +82,7 @@ uint8_t skele_video_init(skele_video_config_t cfg) SDL_DisplayID display; SDL_WindowFlags flags = 0; const SDL_DisplayMode *mode; - uint16_t window_w, window_h, aw, ah; + uint16_t window_w, window_h; if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) { stk_log(STK_LOG_ERROR, "video: SDL_Init failed: %s", @@ -125,24 +125,17 @@ uint8_t skele_video_init(skele_video_config_t cfg) return SKELE_INIT_FAILURE; } - aw = (uint16_t)((mode->w * 3) / 4); - ah = (uint16_t)((mode->h * 3) / 4); - cur_scale = 1; - while ((vid_w * (cur_scale + 1)) <= aw && - (vid_h * (cur_scale + 1)) <= ah) - cur_scale++; - + cur_scale = max_scale(vid_w, vid_h); window_w = vid_w * cur_scale; window_h = vid_h * cur_scale; } - rgba_buf = malloc(vid_total * sizeof(uint32_t)); + rgba_buf = calloc(vid_total, sizeof(uint32_t)); if (!rgba_buf) { stk_log(STK_LOG_ERROR, "video: out of memory"); SDL_Quit(); return SKELE_INIT_FAILURE; } - memset(rgba_buf, 0, vid_total * sizeof(uint32_t)); window = SDL_CreateWindow("skele", window_w, window_h, flags | SDL_WINDOW_HIDDEN);