From 41133b4b2f52c4ec95706b505cc77a6ac754a712 Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Tue, 3 Sep 2024 02:49:25 +1000 Subject: [PATCH] cl_capturevideo: handle failure to open the video file Fixes https://gitlab.com/xonotic/darkplaces/-/issues/72 Shuts down when -capturedemo cmdline fails instead of leaving the demo running. Signed-off-by: bones_was_here --- cap_avi.c | 6 ++++++ cap_ogg.c | 6 ++++++ cl_screen.c | 13 +++++++++++++ 3 files changed, 25 insertions(+) diff --git a/cap_avi.c b/cap_avi.c index 80199c9e..df06faa1 100644 --- a/cap_avi.c +++ b/cap_avi.c @@ -507,6 +507,12 @@ void SCR_CaptureVideo_Avi_BeginVideo(void) cls.capturevideo.format = CAPTUREVIDEOFORMAT_AVI_I420; cls.capturevideo.formatextension = "avi"; cls.capturevideo.videofile = FS_OpenRealFile(va(vabuf, sizeof(vabuf), "%s.%s", cls.capturevideo.basename, cls.capturevideo.formatextension), "wb", false); + if (!cls.capturevideo.videofile) + { + Con_Printf(CON_ERROR "Failed to open video file \"%s\", cancelling video capture.\n", vabuf); + cls.capturevideo.error = true; + return; + } cls.capturevideo.writeEndVideo = SCR_CaptureVideo_Avi_EndVideo; cls.capturevideo.writeVideoFrame = SCR_CaptureVideo_Avi_VideoFrames; cls.capturevideo.writeSoundFrame = SCR_CaptureVideo_Avi_SoundFrame; diff --git a/cap_ogg.c b/cap_ogg.c index 8e546caf..096c2675 100644 --- a/cap_ogg.c +++ b/cap_ogg.c @@ -924,6 +924,12 @@ void SCR_CaptureVideo_Ogg_BeginVideo(void) cls.capturevideo.format = CAPTUREVIDEOFORMAT_OGG_VORBIS_THEORA; cls.capturevideo.formatextension = "ogv"; cls.capturevideo.videofile = FS_OpenRealFile(va(vabuf, sizeof(vabuf), "%s.%s", cls.capturevideo.basename, cls.capturevideo.formatextension), "wb", false); + if (!cls.capturevideo.videofile) + { + Con_Printf(CON_ERROR "Failed to open video file \"%s\", cancelling video capture.\n", vabuf); + cls.capturevideo.error = true; + return; + } cls.capturevideo.writeEndVideo = SCR_CaptureVideo_Ogg_EndVideo; cls.capturevideo.writeVideoFrame = SCR_CaptureVideo_Ogg_VideoFrames; cls.capturevideo.writeSoundFrame = SCR_CaptureVideo_Ogg_SoundFrame; diff --git a/cl_screen.c b/cl_screen.c index 2b03e0f7..34c06f37 100644 --- a/cl_screen.c +++ b/cl_screen.c @@ -1174,6 +1174,11 @@ void SCR_CaptureVideo_EndVideo(void) cls.capturevideo.outbuffer = NULL; } + // If demo capture failed don't leave the demo playing. + // CL_StopPlayback shuts down when demo capture finishes successfully. + if (cls.capturevideo.error && Sys_CheckParm("-capturedemo")) + host.state = host_shutdown; + memset(&cls.capturevideo, 0, sizeof(cls.capturevideo)); } @@ -1192,6 +1197,14 @@ static void SCR_CaptureVideo(void) { if (!cls.capturevideo.active) SCR_CaptureVideo_BeginVideo(); + if (cls.capturevideo.error) + { + // specific error message was printed already + Cvar_SetValueQuick(&cl_capturevideo, 0); + SCR_CaptureVideo_EndVideo(); + return; + } + if (cls.capturevideo.framerate != cl_capturevideo_fps.value * cl_capturevideo_framestep.integer) { Con_Printf(CON_WARN "You can not change the video framerate while recording a video.\n"); -- 2.39.2