From 9f9ada8f8d42aa45eb67eae2a7a7c4f1cc5094fa Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 2 Apr 2012 04:22:22 +0000 Subject: [PATCH] Fix race condition that could result in a crash when opening video When opening the video resulted in the script resolution changing, the subtitles file was committed at a time when IsLoaded() would return true but VideoOpen hadn't been signalled yet, resulting in some VideoDisplay code running before the display was initialized. If the video opened is sufficiently fast to decode, this could result in a crash due to trying to display a frame before the display is shown. Originally committed to SVN as r6645. --- aegisub/src/video_context.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aegisub/src/video_context.cpp b/aegisub/src/video_context.cpp index 21889b507..60551a78f 100644 --- a/aegisub/src/video_context.cpp +++ b/aegisub/src/video_context.cpp @@ -139,6 +139,7 @@ void VideoContext::SetVideo(const wxString &filename) { return; } + bool commit_subs = false; try { provider.reset(new ThreadedFrameSource(filename, this)); videoProvider = provider->GetVideoProvider(); @@ -155,7 +156,7 @@ void VideoContext::SetVideo(const wxString &filename) { if (sx == 0 && sy == 0) { context->ass->SetScriptInfo("PlayResX", wxString::Format("%d", vx)); context->ass->SetScriptInfo("PlayResY", wxString::Format("%d", vy)); - context->ass->Commit(_("Change script resolution"), AssFile::COMMIT_SCRIPTINFO); + commit_subs = true; } // If it has been set to something other than a multiple of the video // resolution, ask the user if they want it to be fixed @@ -173,7 +174,7 @@ void VideoContext::SetVideo(const wxString &filename) { case 2: // Always change script res context->ass->SetScriptInfo("PlayResX", wxString::Format("%d", vx)); context->ass->SetScriptInfo("PlayResY", wxString::Format("%d", vy)); - context->ass->Commit(_("change script resolution"), AssFile::COMMIT_SCRIPTINFO); + commit_subs = true; break; default: // Never change break; @@ -226,6 +227,9 @@ void VideoContext::SetVideo(const wxString &filename) { catch (VideoProviderError const& err) { wxMessageBox(lagi_wxString(err.GetMessage()), "Error setting video", wxOK | wxICON_ERROR | wxCENTER); } + + if (commit_subs) + context->ass->Commit(_("change script resolution"), AssFile::COMMIT_SCRIPTINFO); } void VideoContext::Reload() {