From 8cf71ddd8d5f852b6b8905537cc37cb72efb24fb Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 18 Jan 2012 20:08:16 +0000 Subject: [PATCH] Fix crash when seeking to previous keyframe with no keyframes loaded Originally committed to SVN as r6305. --- aegisub/src/command/video.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/aegisub/src/command/video.cpp b/aegisub/src/command/video.cpp index 108c08ec5..0fccea4cc 100644 --- a/aegisub/src/command/video.cpp +++ b/aegisub/src/command/video.cpp @@ -451,9 +451,14 @@ struct video_frame_prev_keyframe : public validator_video_loaded { STR_HELP("Seek to the previous keyframe.") void operator()(agi::Context *c) { - int frame = c->videoController->GetFrameN(); std::vector const& kf = c->videoController->GetKeyFrames(); - std::vector::const_iterator pos = lower_bound(kf.begin(), kf.end(), frame); + if (kf.empty()) { + c->videoController->JumpToFrame(0); + return; + } + + std::vector::const_iterator pos = + lower_bound(kf.begin(), kf.end(), c->videoController->GetFrameN()); if (pos != kf.begin()) --pos;