From de37ca8e2c85703fb6b8b5763a73fd9b16a79dfb Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 9 May 2021 13:20:53 +0200 Subject: [PATCH] Catch exceptions in VideoThread --- CHANGELOG.md | 1 + extern/osg-ffmpeg-videoplayer/videostate.cpp | 57 +++++++++++--------- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 856e104389..154f8639ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,6 +121,7 @@ Bug #5975: NIF controllers from sheath meshes are used Bug #5991: Activate should always be allowed for inventory items Bug #5995: NiUVController doesn't calculate the UV offset properly + Bug #6007: Crash when ending cutscene is playing Bug #6016: Greeting interrupts Fargoth's sneak-walk Feature #390: 3rd person look "over the shoulder" Feature #832: OpenMW-CS: Handle deleted references diff --git a/extern/osg-ffmpeg-videoplayer/videostate.cpp b/extern/osg-ffmpeg-videoplayer/videostate.cpp index c153aa14c7..d6c99051e5 100644 --- a/extern/osg-ffmpeg-videoplayer/videostate.cpp +++ b/extern/osg-ffmpeg-videoplayer/videostate.cpp @@ -409,43 +409,50 @@ public: pFrame = av_frame_alloc(); - while(self->videoq.get(packet, self) >= 0) + try { - if(packet->data == flush_pkt.data) + while(self->videoq.get(packet, self) >= 0) { - avcodec_flush_buffers(self->video_ctx); + if(packet->data == flush_pkt.data) + { + avcodec_flush_buffers(self->video_ctx); - self->pictq_mutex.lock(); - self->pictq_size = 0; - self->pictq_rindex = 0; - self->pictq_windex = 0; - self->pictq_mutex.unlock(); + self->pictq_mutex.lock(); + self->pictq_size = 0; + self->pictq_rindex = 0; + self->pictq_windex = 0; + self->pictq_mutex.unlock(); - self->frame_last_pts = packet->pts * av_q2d((*self->video_st)->time_base); - continue; - } + self->frame_last_pts = packet->pts * av_q2d((*self->video_st)->time_base); + continue; + } - // Decode video frame - int ret = avcodec_send_packet(self->video_ctx, packet); - // EAGAIN is not expected - if (ret < 0) - throw std::runtime_error("Error decoding video frame"); + // Decode video frame + int ret = avcodec_send_packet(self->video_ctx, packet); + // EAGAIN is not expected + if (ret < 0) + throw std::runtime_error("Error decoding video frame"); - while (!ret) - { - ret = avcodec_receive_frame(self->video_ctx, pFrame); - if (!ret) + while (!ret) { - double pts = pFrame->best_effort_timestamp; - pts *= av_q2d((*self->video_st)->time_base); + ret = avcodec_receive_frame(self->video_ctx, pFrame); + if (!ret) + { + double pts = pFrame->best_effort_timestamp; + pts *= av_q2d((*self->video_st)->time_base); - pts = self->synchronize_video(pFrame, pts); + pts = self->synchronize_video(pFrame, pts); - if(self->queue_picture(pFrame, pts) < 0) - break; + if(self->queue_picture(pFrame, pts) < 0) + break; + } } } } + catch(std::exception& e) + { + std::cerr << "An error occurred playing the video: " << e.what () << std::endl; + } av_packet_unref(packet);