From f68cc1e584b1198fd2a212eb3fed3c0d02ed6417 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 16 Apr 2013 20:21:06 -0700 Subject: [PATCH] Fix crash when opening kanji timer dialog. Closes #1585. --- aegisub/src/dialog_kara_timing_copy.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/aegisub/src/dialog_kara_timing_copy.cpp b/aegisub/src/dialog_kara_timing_copy.cpp index 9ec86c4cf..397f78842 100644 --- a/aegisub/src/dialog_kara_timing_copy.cpp +++ b/aegisub/src/dialog_kara_timing_copy.cpp @@ -271,13 +271,10 @@ void KaraokeLineMatchDisplay::OnPaint(wxPaintEvent &) // Matched destination text { - int adv = DrawBoxedText(dc, grp.dst, next_x, y_line2); + const int adv = DrawBoxedText(dc, grp.dst, next_x, y_line2); // Adjust next_x here while we have the text_w - if (syl_x > next_x + adv) - next_x = syl_x; - else - next_x = next_x + adv; + next_x = syl_x > next_x + adv ? syl_x : next_x + adv; } // Spacing between groups @@ -310,22 +307,20 @@ void KaraokeLineMatchDisplay::OnPaint(wxPaintEvent &) } // Remaining destination - std::string txt = unmatched_destination.substr(0, destination_sel_length); - if (!txt.empty()) + if (!unmatched_destination.empty()) { dc.SetTextBackground(sel_back); dc.SetTextForeground(sel_text); dc.SetBrush(wxBrush(sel_back)); - next_x += DrawBoxedText(dc, txt, next_x, y_line2); + next_x += DrawBoxedText(dc, unmatched_destination.substr(0, destination_sel_length), next_x, y_line2); } - txt = unmatched_destination.substr(destination_sel_length); - if (!txt.empty()) + if (destination_sel_length < unmatched_destination.size()) { dc.SetTextBackground(inner_back); dc.SetTextForeground(inner_text); dc.SetBrush(wxBrush(inner_back)); - DrawBoxedText(dc, txt, next_x, y_line2); + DrawBoxedText(dc, unmatched_destination.substr(destination_sel_length), next_x, y_line2); } }