From 8d2016bbef1adb2e469b1c3bb650ed891b099b98 Mon Sep 17 00:00:00 2001 From: Ayose Date: Fri, 15 Jul 2022 20:35:53 +0100 Subject: Initialize cell dimensions when create a Graphics instance. This fixes a bug that crashes the terminal when a graphic is added before resizing the window. --- alacritty_terminal/src/graphics/mod.rs | 10 +++++++++- alacritty_terminal/src/term/mod.rs | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/alacritty_terminal/src/graphics/mod.rs b/alacritty_terminal/src/graphics/mod.rs index b6f58a11..4641a912 100644 --- a/alacritty_terminal/src/graphics/mod.rs +++ b/alacritty_terminal/src/graphics/mod.rs @@ -296,6 +296,14 @@ pub struct Graphics { } impl Graphics { + /// Create a new instance, and initialize it with the dimensions of the + /// window. + pub fn new(size: &S) -> Self { + let mut graphics = Graphics::default(); + graphics.resize(size); + graphics + } + /// Generate a new graphic identifier. pub fn next_id(&mut self) -> GraphicId { self.last_id += 1; @@ -333,7 +341,7 @@ impl Graphics { } /// Update cell dimensions. - pub fn resize(&mut self, size: S) { + pub fn resize(&mut self, size: &S) { self.cell_height = size.cell_height(); self.cell_width = size.cell_width(); } diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index 4fc4032b..b02e40f4 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -373,7 +373,7 @@ impl Term { title: None, title_stack: Vec::new(), selection: None, - graphics: Graphics::default(), + graphics: Graphics::new(dimensions), damage, } } @@ -665,7 +665,7 @@ impl Term { self.damage.resize(num_cols, num_lines); // Update size information for graphics. - self.graphics.resize(size); + self.graphics.resize(&size); } /// Active terminal modes. -- cgit