From a2ac368bdcc3db50b58acbcf6a0ccf3f0dce8a75 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 9 Apr 2022 13:42:13 +0200 Subject: [PATCH 1/4] Attempted fix for a crash reported on Discord --- epaint/src/text/text_layout.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/epaint/src/text/text_layout.rs b/epaint/src/text/text_layout.rs index a03978cd0c7..5554f98528e 100644 --- a/epaint/src/text/text_layout.rs +++ b/epaint/src/text/text_layout.rs @@ -172,7 +172,9 @@ fn rows_from_paragraphs( }); } else { line_break(fonts, ¶graph, job, &mut rows); - rows.last_mut().unwrap().ends_with_newline = !is_last_paragraph; + if let Some(last_row) = rows.last_mut() { + last_row.ends_with_newline = !is_last_paragraph; + } } } } From 2d21b350794a6efafe7b8d3ab16ebd60d9839198 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 9 Apr 2022 15:01:51 +0200 Subject: [PATCH 2/4] Add unit test --- epaint/src/text/text_layout.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/epaint/src/text/text_layout.rs b/epaint/src/text/text_layout.rs index 5554f98528e..47355636c06 100644 --- a/epaint/src/text/text_layout.rs +++ b/epaint/src/text/text_layout.rs @@ -775,3 +775,14 @@ fn is_chinese(c: char) -> bool { || ('\u{3400}' <= c && c <= '\u{4DBF}') || ('\u{2B740}' <= c && c <= '\u{2B81F}') } + +// ---------------------------------------------------------------------------- + +#[test] +fn test_zero_max_width() { + let mut fonts = FontsImpl::new(1.0, 1024, super::FontDefinitions::default()); + let mut layout_job = LayoutJob::single_section("W".into(), super::TextFormat::default()); + layout_job.wrap.max_width = 0.0; + let galley = super::layout(&mut fonts, layout_job.into()); + assert_eq!(galley.rows.len(), 1); +} From 5cf1b6e3821f18211a504769489799a04ae1a6a5 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 9 Apr 2022 20:18:27 +0200 Subject: [PATCH 3/4] Fix text layout bug added in https://github.com/emilk/egui/pull/1291 Using `max_rows == 0` as a special case was a bad idea. --- epaint/src/text/text_layout.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epaint/src/text/text_layout.rs b/epaint/src/text/text_layout.rs index 47355636c06..c650ca45d89 100644 --- a/epaint/src/text/text_layout.rs +++ b/epaint/src/text/text_layout.rs @@ -251,7 +251,7 @@ fn line_break( } if row_start_idx < paragraph.glyphs.len() { - if non_empty_rows == job.wrap.max_rows { + if job.wrap.max_rows > 0 && non_empty_rows == job.wrap.max_rows { if let Some(last_row) = out_rows.last_mut() { replace_last_glyph_with_overflow_character(fonts, job, last_row); } From ba061b8ea45d0d1154e300055bab5e68fe2d6932 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 9 Apr 2022 20:18:38 +0200 Subject: [PATCH 4/4] Revert "Attempted fix for a crash reported on Discord" This reverts commit a2ac368bdcc3db50b58acbcf6a0ccf3f0dce8a75. --- epaint/src/text/text_layout.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/epaint/src/text/text_layout.rs b/epaint/src/text/text_layout.rs index c650ca45d89..eacc09584a0 100644 --- a/epaint/src/text/text_layout.rs +++ b/epaint/src/text/text_layout.rs @@ -172,9 +172,7 @@ fn rows_from_paragraphs( }); } else { line_break(fonts, ¶graph, job, &mut rows); - if let Some(last_row) = rows.last_mut() { - last_row.ends_with_newline = !is_last_paragraph; - } + rows.last_mut().unwrap().ends_with_newline = !is_last_paragraph; } } }