From 2bf92fec6e776cda4337672cbbeb12d30ec0681e Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 29 Dec 2012 08:40:10 -0800 Subject: [PATCH] Fix crash when amending commits with video open The video source's copy of the subtitle file was being discarded once it was fully loaded (as it was previously never needed again), so amending it only worked if the user had made a non-amend commit after the last seek. --- aegisub/src/threaded_frame_source.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/aegisub/src/threaded_frame_source.cpp b/aegisub/src/threaded_frame_source.cpp index b53b68a9d..1db868a6d 100644 --- a/aegisub/src/threaded_frame_source.cpp +++ b/aegisub/src/threaded_frame_source.cpp @@ -36,6 +36,11 @@ #include "video_frame.h" #include "video_provider_manager.h" +enum { + NEW_SUBS_FILE = -1, + SUBS_FILE_ALREADY_LOADED = -2 +}; + // Test if a line is a dialogue line which is not visible at the given time struct invisible_line : public std::unary_function { double time; @@ -65,14 +70,18 @@ std::shared_ptr ThreadedFrameSource::ProcFrame(int frameNum, dou if (!raw && provider) { try { wxMutexLocker locker(fileMutex); - if (subs.get() && singleFrame != frameNum) { + if (subs && singleFrame != frameNum && singleFrame != SUBS_FILE_ALREADY_LOADED) { // Generally edits and seeks come in groups; if the last thing done // was seek it is more likely that the user will seek again and // vice versa. As such, if this is the first frame requested after // an edit, only export the currently visible lines (because the // other lines will probably not be viewed before the file changes // again), and if it's a different frame, export the entire file. - if (singleFrame == -1) { + if (singleFrame != NEW_SUBS_FILE) { + provider->LoadSubtitles(subs.get()); + singleFrame = SUBS_FILE_ALREADY_LOADED; + } + else { // This will crash if any of the export filters try to use // anything but the subtitles, but that wouldn't be safe to // do anyway @@ -99,16 +108,12 @@ std::shared_ptr ThreadedFrameSource::ProcFrame(int frameNum, dou subs->Line.clear(); boost::push_back(subs->Line, full | boost::adaptors::indirected); } - catch(...) { + catch (...) { subs->Line.clear(); boost::push_back(subs->Line, full | boost::adaptors::indirected); throw; } } - else { - provider->LoadSubtitles(subs.get()); - subs.reset(); - } } } catch (wxString const& err) { throw SubtitlesProviderErrorEvent(err); } @@ -160,7 +165,7 @@ void *ThreadedFrameSource::Entry() { } } - singleFrame = -1; + singleFrame = NEW_SUBS_FILE; } try {