fix of infinite loop in notification lines calulating #6583

fix of infinite loop in notification lines calulating
This commit is contained in:
David Kocik 2021-06-03 17:24:20 +02:00
parent 5b706b98f4
commit a30f9f6781

View File

@ -413,25 +413,27 @@ void NotificationManager::PopNotification::init()
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
int 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()) {
int 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);
} }
// when one word longer than line. } else {
if (ImGui::CalcTextSize(text.substr(last_end, next_space - last_end).c_str()).x > m_window_width - m_window_width_offset) { next_space = text.length();
float width_of_a = ImGui::CalcTextSize("a").x; }
int letter_count = (int)((m_window_width - m_window_width_offset) / width_of_a); // when one word longer than line.
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) { if (ImGui::CalcTextSize(text.substr(last_end, next_space - last_end).c_str()).x > m_window_width - m_window_width_offset) {
letter_count++; float width_of_a = ImGui::CalcTextSize("a").x;
} int letter_count = (int)((m_window_width - m_window_width_offset) / width_of_a);
m_endlines.push_back(last_end + letter_count); 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) {
last_end += letter_count; letter_count++;
} else {
m_endlines.push_back(next_space);
last_end = next_space + 1;
} }
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 { else {