0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

screenshot: fix segfault when taking a screenshot without video

Also a style change to exit early when nothing can be done anymore.
This commit is contained in:
Christoph Heinrich 2023-03-04 21:26:37 +01:00 committed by Dudemanguy
parent 31160ff941
commit 855b619cc9

View File

@ -337,7 +337,9 @@ static struct mp_image *screenshot_get(struct MPContext *mpctx, int mode,
mode = 0;
bool need_add_subs = mode == MODE_SUBTITLES;
if (mpctx->video_out && mpctx->video_out->config_ok) {
if (!mpctx->video_out || !mpctx->video_out->config_ok)
return NULL;
vo_wait_frame(mpctx->video_out); // important for each-frame mode
struct voctrl_screenshot ctrl = {
@ -359,17 +361,19 @@ static struct mp_image *screenshot_get(struct MPContext *mpctx, int mode,
vo_control(mpctx->video_out, VOCTRL_SCREENSHOT_WIN, &image);
mode = MODE_FULL_WINDOW;
}
}
if (!image)
return NULL;
if (image && (image->fmt.flags & MP_IMGFLAG_HWACCEL)) {
if (image->fmt.flags & MP_IMGFLAG_HWACCEL) {
struct mp_image *nimage = mp_image_hw_download(image, NULL);
talloc_free(image);
if (!nimage)
return NULL;
image = nimage;
}
if (image && need_add_subs)
if (need_add_subs)
add_subs(mpctx, image);
mp_image_params_guess_csp(&image->params);
return image;
}