From e790e8e718963560d2da671cf76481b3ee883405 Mon Sep 17 00:00:00 2001 From: 13r0ck Date: Tue, 28 Mar 2023 16:30:53 -0600 Subject: [PATCH] use checked_sub to fix panic on window resize. bug link: https://github.com/iced-rs/iced/issues/1773 --- src/buffer.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 497cafd..123ce38 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -243,14 +243,16 @@ impl<'b> Iterator for LayoutRunIter<'b> { return None; } - self.remaining_len -= 1; - return Some(LayoutRun { - line_i: self.line_i, - text: line.text(), - rtl: shape.rtl, - glyphs: &layout_line.glyphs, - line_y: self.line_y, - line_w: layout_line.w, + return self.remaining_len.checked_sub(1).map(|num| { + self.remaining_len = num; + LayoutRun { + line_i: self.line_i, + text: line.text(), + rtl: shape.rtl, + glyphs: &layout_line.glyphs, + line_y: self.line_y, + line_w: layout_line.w, + } }); } self.line_i += 1;