From c08a9d4d7d87a42c7c1d0ccf8abe09007ef85d59 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 14 Jan 2013 08:15:12 -0800 Subject: [PATCH] Always make a full copy of the subtitles for ThreadedFrameSource after a save Saving can add new lines to the file without making a commit, resulting in the rendering thread's copy of the file getting out of sync. --- aegisub/src/video_context.cpp | 9 ++++++--- aegisub/src/video_context.h | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/aegisub/src/video_context.cpp b/aegisub/src/video_context.cpp index 5970e68de..f2d6e9301 100644 --- a/aegisub/src/video_context.cpp +++ b/aegisub/src/video_context.cpp @@ -63,8 +63,6 @@ #include "video_context.h" #include "video_frame.h" -/// @brief Constructor -/// VideoContext::VideoContext() : playback(this) , startMS(0) @@ -74,6 +72,7 @@ VideoContext::VideoContext() , arType(0) , hasSubtitles(false) , playAudioOnStep(OPT_GET("Audio/Plays When Stepping Video")) +, no_amend(false) { Bind(EVT_VIDEO_ERROR, &VideoContext::OnVideoError, this); Bind(EVT_SUBTITLES_ERROR, &VideoContext::OnSubtitlesError, this); @@ -236,15 +235,19 @@ void VideoContext::Reload() { void VideoContext::OnSubtitlesCommit(int type, std::set const& changed) { if (!IsLoaded()) return; - if (changed.empty()) + if (changed.empty() || no_amend) provider->LoadSubtitles(context->ass); else provider->UpdateSubtitles(context->ass, changed); if (!IsPlaying()) GetFrameAsync(frame_n); + + no_amend = false; } void VideoContext::OnSubtitlesSave() { + no_amend = true; + context->ass->SetScriptInfo("VFR File", MakeRelativePath(GetTimecodesName(), context->ass->filename)); context->ass->SetScriptInfo("Keyframes File", MakeRelativePath(GetKeyFramesName(), context->ass->filename)); diff --git a/aegisub/src/video_context.h b/aegisub/src/video_context.h index 37e4e4fa2..d69ac9749 100644 --- a/aegisub/src/video_context.h +++ b/aegisub/src/video_context.h @@ -130,6 +130,12 @@ class VideoContext : public wxEvtHandler { /// Cached option for audio playing when frame stepping const agi::OptionValue* playAudioOnStep; + /// Amending the frame source's copy of the subtitle file requires that it + /// be kept in perfect sync. Saving the file can add lines to the file + /// without a commit, breaking this sync, so force a non-amend after each + /// save. + bool no_amend; + void OnPlayTimer(wxTimerEvent &event); /// The timecodes from the video file