From 2b38a48ef98f04a2769a9e5f56978aed5e49555e Mon Sep 17 00:00:00 2001 From: Sergey Svishchev Date: Sun, 28 Sep 2025 16:23:22 +0300 Subject: [PATCH 1/2] VIDEO: handle error conditions and uninitialized displays when taking a screenshot. --- sim_video.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sim_video.c b/sim_video.c index e1e0c13c1..47b9dbfd5 100644 --- a/sim_video.c +++ b/sim_video.c @@ -2613,7 +2613,13 @@ if (!fullname) if (1) { SDL_Surface *sshot = sim_end ? SDL_CreateRGBSurface(0, vptr->vid_width, vptr->vid_height, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000) : SDL_CreateRGBSurface(0, vptr->vid_width, vptr->vid_height, 32, 0x0000ff00, 0x000ff000, 0xff000000, 0x000000ff) ; - SDL_RenderReadPixels(vptr->vid_renderer, NULL, SDL_PIXELFORMAT_ARGB8888, sshot->pixels, sshot->pitch); + if (!sshot) + return SCPE_MEM; + if (SDL_RenderReadPixels(vptr->vid_renderer, NULL, SDL_PIXELFORMAT_ARGB8888, sshot->pixels, sshot->pitch) != 0) { + SDL_FreeSurface(sshot); + sim_printf ("Error creating screenshot: %s\n", SDL_GetError()); + return SCPE_ARG | SCPE_NOMESSAGE; + } #if defined(HAVE_LIBPNG) if (!match_ext (filename, "bmp")) { sprintf (fullname, "%s%s", filename, match_ext (filename, "png") ? "" : ".png"); @@ -2663,6 +2669,8 @@ else { } strncpy (name, _screenshot_filename, n); for (vptr = &vid_first; vptr != NULL; vptr = vptr->next) { + if (vptr->vid_width == 0) + continue; if (vid_active > 1) sprintf (name + n, "%d%s", i++, extension); else From ceec74a0e05281be8fcf705434eb1051d5c4b6f1 Mon Sep 17 00:00:00 2001 From: Sergey Svishchev Date: Wed, 1 Oct 2025 19:30:06 +0300 Subject: [PATCH 2/2] Expand tabs. --- sim_video.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sim_video.c b/sim_video.c index 47b9dbfd5..d320a5075 100644 --- a/sim_video.c +++ b/sim_video.c @@ -2614,12 +2614,12 @@ if (1) { SDL_Surface *sshot = sim_end ? SDL_CreateRGBSurface(0, vptr->vid_width, vptr->vid_height, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000) : SDL_CreateRGBSurface(0, vptr->vid_width, vptr->vid_height, 32, 0x0000ff00, 0x000ff000, 0xff000000, 0x000000ff) ; if (!sshot) - return SCPE_MEM; + return SCPE_MEM; if (SDL_RenderReadPixels(vptr->vid_renderer, NULL, SDL_PIXELFORMAT_ARGB8888, sshot->pixels, sshot->pitch) != 0) { - SDL_FreeSurface(sshot); - sim_printf ("Error creating screenshot: %s\n", SDL_GetError()); - return SCPE_ARG | SCPE_NOMESSAGE; - } + SDL_FreeSurface(sshot); + sim_printf ("Error creating screenshot: %s\n", SDL_GetError()); + return SCPE_ARG | SCPE_NOMESSAGE; + } #if defined(HAVE_LIBPNG) if (!match_ext (filename, "bmp")) { sprintf (fullname, "%s%s", filename, match_ext (filename, "png") ? "" : ".png");