capture_screen: check for errors

This commit is contained in:
Sigrid Solveig Haflínudóttir 2023-07-10 15:35:35 +00:00
parent ff6d9e39ca
commit 05356e23b1
1 changed files with 6 additions and 4 deletions

View File

@ -289,14 +289,16 @@ capture_screen(void)
int w, h; int w, h;
SDL_Surface *surface; SDL_Surface *surface;
SDL_GetRendererOutputSize(emu_renderer, &w, &h); SDL_GetRendererOutputSize(emu_renderer, &w, &h);
surface = SDL_CreateRGBSurface(0, w, h, 24, Rmask, Gmask, Bmask, 0); if((surface = SDL_CreateRGBSurface(0, w, h, 24, Rmask, Gmask, Bmask, 0)) == NULL)
return;
SDL_RenderReadPixels(emu_renderer, NULL, format, surface->pixels, surface->pitch); SDL_RenderReadPixels(emu_renderer, NULL, format, surface->pixels, surface->pitch);
strftime(fname, sizeof(fname), "screenshot-%Y%m%d-%H%M%S.bmp", localtime(&t)); strftime(fname, sizeof(fname), "screenshot-%Y%m%d-%H%M%S.bmp", localtime(&t));
SDL_SaveBMP(surface, fname); if(SDL_SaveBMP(surface, fname) == 0){
SDL_FreeSurface(surface);
fprintf(stderr, "Saved %s\n", fname); fprintf(stderr, "Saved %s\n", fname);
fflush(stderr); fflush(stderr);
} }
SDL_FreeSurface(surface);
}
static void static void
restart(Uxn *u) restart(Uxn *u)