]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
cl_capturevideo: handle failure to open the video file
authorbones_was_here <bones_was_here@xonotic.au>
Mon, 2 Sep 2024 16:49:25 +0000 (02:49 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Thu, 12 Sep 2024 13:53:34 +0000 (23:53 +1000)
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 <bones_was_here@xonotic.au>
cap_avi.c
cap_ogg.c
cl_screen.c

index 80199c9e08a1ad548f858cf2e0601186230a04c0..df06faa10ed6ec97c6c6862a236525903799cbe7 100644 (file)
--- 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;
index 8e546caf5b653f4c4382ac0c8a2fab9f74a022f4..096c26751333f10a57a0d0bbbe8e2056c3da8828 100644 (file)
--- 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;
index 2b03e0f71aadf9352a1aa8d2a4abeeec7c5d98ad..34c06f376f89ffd821cbd0167c97eb66802f1715 100644 (file)
@@ -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");