From 747e34b981099cb4ef270b3bd59ed53602c4334d Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 9 Nov 2013 15:56:09 -0800 Subject: [PATCH] Fix crash when a subtitles file is not found --- aegisub/src/subs_controller.cpp | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/aegisub/src/subs_controller.cpp b/aegisub/src/subs_controller.cpp index c2164d610..5bf93544a 100644 --- a/aegisub/src/subs_controller.cpp +++ b/aegisub/src/subs_controller.cpp @@ -84,32 +84,32 @@ SubsController::SubsController(agi::Context *context) void SubsController::Load(agi::fs::path const& filename, std::string charset) { try { - if (charset.empty()) - charset = CharSetDetect::GetEncoding(filename); - } - catch (agi::UserCancelException const&) { - return; - } - - // Make sure that file isn't actually a timecode file - if (charset != "binary") { try { - TextFileReader testSubs(filename, charset); - std::string cur = testSubs.ReadLineFromFile(); - if (boost::starts_with(cur, "# timecode")) { - context->videoController->LoadTimecodes(filename); - return; + if (charset.empty()) + charset = CharSetDetect::GetEncoding(filename); + } + catch (agi::UserCancelException const&) { + return; + } + + // Make sure that file isn't actually a timecode file + if (charset != "binary") { + try { + TextFileReader testSubs(filename, charset); + std::string cur = testSubs.ReadLineFromFile(); + if (boost::starts_with(cur, "# timecode")) { + context->videoController->LoadTimecodes(filename); + return; + } + } + catch (...) { + // if trying to load the file as timecodes fails it's fairly + // safe to assume that it is in fact not a timecode file } } - catch (...) { - // if trying to load the file as timecodes fails it's fairly - // safe to assume that it is in fact not a timecode file - } - } - const SubtitleFormat *reader = SubtitleFormat::GetReader(filename, charset); + const SubtitleFormat *reader = SubtitleFormat::GetReader(filename, charset); - try { AssFile temp; reader->ReadFile(&temp, filename, charset);