From fd0204cc425bc9c204f51bc0006083de6e7b6fd3 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Mon, 19 Mar 2018 15:50:08 +0100 Subject: [PATCH] SWITCH: prevent fb overflow in case of external resolution change --- src/video/switch/SDL_switchvideo.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/video/switch/SDL_switchvideo.c b/src/video/switch/SDL_switchvideo.c index 0ccfb0eec..aee219b3b 100644 --- a/src/video/switch/SDL_switchvideo.c +++ b/src/video/switch/SDL_switchvideo.c @@ -184,9 +184,19 @@ static int SWITCH_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_R { SWITCH_WindowData *data = (SWITCH_WindowData *) SDL_GetWindowData(window, SWITCH_DATA); - u32 *src = (u32 *) data->surface->pixels; - u32 *dst = (u32 *) gfxGetFramebuffer(NULL, NULL); + u32 fb_w, fb_h; int x, y, w = window->w, h = window->h; + u32 *src = (u32 *) data->surface->pixels; + u32 *dst = (u32 *) gfxGetFramebuffer(&fb_w, &fb_h); + + // prevent framebuffer overflow in case of resolution change outside SDL, + // which should not happen + if(window->x + w > fb_w) { + w = fb_w - window->x; + } + if(window->y + h > fb_h) { + h = fb_h - window->y; + } for (y = 0; y < h; y++) { for (x = 0; x < w; x += 4) {