image: Check realized before using surface

This avoids crashes in early calls to scaling()
This commit is contained in:
Sophie Herold 2023-12-26 18:34:52 +01:00
parent 3c73c06241
commit e387d8dc66

View file

@ -276,9 +276,13 @@ impl LpImage {
} }
pub fn scaling(&self) -> f64 { pub fn scaling(&self) -> f64 {
self.native() if self.is_realized() {
.map(|x| x.surface().scale()) self.native()
.unwrap_or_else(|| self.scale_factor() as f64) .map(|x| x.surface().scale())
.unwrap_or_else(|| self.scale_factor() as f64)
} else {
1.
}
} }
/// Monitor size in physical pixels /// Monitor size in physical pixels