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.
This commit is contained in:
Thomas Goyne 2012-04-02 04:22:22 +00:00
parent 4d50efc256
commit 9f9ada8f8d

View file

@ -139,6 +139,7 @@ void VideoContext::SetVideo(const wxString &filename) {
return; return;
} }
bool commit_subs = false;
try { try {
provider.reset(new ThreadedFrameSource(filename, this)); provider.reset(new ThreadedFrameSource(filename, this));
videoProvider = provider->GetVideoProvider(); videoProvider = provider->GetVideoProvider();
@ -155,7 +156,7 @@ void VideoContext::SetVideo(const wxString &filename) {
if (sx == 0 && sy == 0) { if (sx == 0 && sy == 0) {
context->ass->SetScriptInfo("PlayResX", wxString::Format("%d", vx)); context->ass->SetScriptInfo("PlayResX", wxString::Format("%d", vx));
context->ass->SetScriptInfo("PlayResY", wxString::Format("%d", vy)); 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 // 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 // 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 case 2: // Always change script res
context->ass->SetScriptInfo("PlayResX", wxString::Format("%d", vx)); context->ass->SetScriptInfo("PlayResX", wxString::Format("%d", vx));
context->ass->SetScriptInfo("PlayResY", wxString::Format("%d", vy)); context->ass->SetScriptInfo("PlayResY", wxString::Format("%d", vy));
context->ass->Commit(_("change script resolution"), AssFile::COMMIT_SCRIPTINFO); commit_subs = true;
break; break;
default: // Never change default: // Never change
break; break;
@ -226,6 +227,9 @@ void VideoContext::SetVideo(const wxString &filename) {
catch (VideoProviderError const& err) { catch (VideoProviderError const& err) {
wxMessageBox(lagi_wxString(err.GetMessage()), "Error setting video", wxOK | wxICON_ERROR | wxCENTER); 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() { void VideoContext::Reload() {