From 16e2db0cd6191319aab9d3c9d4d3d8a9699014e9 Mon Sep 17 00:00:00 2001 From: remi durand Date: Sat, 5 Jun 2021 11:35:26 +0200 Subject: [PATCH] =?UTF-8?q?notification=20manager=20fix=20n=C2=B04=20fix?= =?UTF-8?q?=20an=20infinite=20loop=20when=20long=20word.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/slic3r/GUI/NotificationManager.cpp | 31 +++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index 4cef5c87a..20d5e4ea7 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -420,22 +420,23 @@ void NotificationManager::PopNotification::init() next_space = next_space_candidate; next_space_candidate = text.find_first_of(' ', next_space + 1); } - // when one word longer than line. - if (ImGui::CalcTextSize(text.substr(last_end, next_space - last_end).c_str()).x > m_window_width - m_window_width_offset) { - float width_of_a = ImGui::CalcTextSize("a").x; - int letter_count = (int)((m_window_width - m_window_width_offset) / width_of_a); - while (last_end + letter_count < text.size() && ImGui::CalcTextSize(text.substr(last_end, letter_count).c_str()).x < m_window_width - m_window_width_offset) { - letter_count++; - } - m_endlines.push_back(last_end + letter_count); - last_end += letter_count; - } else { - m_endlines.push_back(next_space); - last_end = next_space + 1; - } + } else { + next_space = text.length(); } - } - else { + // when one word longer than line. + if (ImGui::CalcTextSize(text.substr(last_end, next_space - last_end).c_str()).x > m_window_width - m_window_width_offset) { + float width_of_a = ImGui::CalcTextSize("a").x; + int letter_count = (int)((m_window_width - m_window_width_offset) / width_of_a); + while (last_end + letter_count < text.size() && ImGui::CalcTextSize(text.substr(last_end, letter_count).c_str()).x < m_window_width - m_window_width_offset) { + letter_count++; + } + m_endlines.push_back(last_end + letter_count); + last_end += letter_count; + } else { + m_endlines.push_back(next_space); + last_end = next_space + 1; + } + } else { m_endlines.push_back(text.length()); last_end = text.length(); }