fix of infinite loop in notification lines calulating #6583

This commit is contained in:
David Kocik 2021-07-02 15:13:03 +02:00
parent fd36cb772d
commit 029330d656

View File

@ -272,13 +272,16 @@ void NotificationManager::PopNotification::count_lines()
// find next suitable endline // find next suitable endline
if (ImGui::CalcTextSize(text.substr(last_end).c_str()).x >= m_window_width - m_window_width_offset) { if (ImGui::CalcTextSize(text.substr(last_end).c_str()).x >= m_window_width - m_window_width_offset) {
// more than one line till end // more than one line till end
size_t next_space = text.find_first_of(' ', last_end); int next_space = text.find_first_of(' ', last_end);
if (next_space > 0) { if (next_space > 0 && next_space < text.length()) {
size_t next_space_candidate = text.find_first_of(' ', next_space + 1); int next_space_candidate = text.find_first_of(' ', next_space + 1);
while (next_space_candidate > 0 && ImGui::CalcTextSize(text.substr(last_end, next_space_candidate - last_end).c_str()).x < m_window_width - m_window_width_offset) { while (next_space_candidate > 0 && ImGui::CalcTextSize(text.substr(last_end, next_space_candidate - last_end).c_str()).x < m_window_width - m_window_width_offset) {
next_space = next_space_candidate; next_space = next_space_candidate;
next_space_candidate = text.find_first_of(' ', next_space + 1); next_space_candidate = text.find_first_of(' ', next_space + 1);
} }
} else {
next_space = text.length();
}
// when one word longer than line. // 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) { 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; float width_of_a = ImGui::CalcTextSize("a").x;
@ -288,13 +291,11 @@ void NotificationManager::PopNotification::count_lines()
} }
m_endlines.push_back(last_end + letter_count); m_endlines.push_back(last_end + letter_count);
last_end += letter_count; last_end += letter_count;
} } else {
else {
m_endlines.push_back(next_space); m_endlines.push_back(next_space);
last_end = next_space + 1; last_end = next_space + 1;
} }
} }
}
else { else {
m_endlines.push_back(text.length()); m_endlines.push_back(text.length());
last_end = text.length(); last_end = text.length();