From 41a99c686b92f0138f3dd1e8eeaf8be399fcaa20 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Mon, 22 Jan 2024 11:10:15 -0700 Subject: [PATCH] Potential fix for #2422 --- crates/gpui/src/platform/mac/window.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index 1ef5d346cc..9e9699fb05 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -1003,9 +1003,21 @@ impl PlatformWindow for MacWindow { } fn get_scale_factor(native_window: id) -> f32 { - unsafe { + let factor = unsafe { let screen: id = msg_send![native_window, screen]; NSScreen::backingScaleFactor(screen) as f32 + }; + + // We are not certain what triggers this, but it seems that sometimes + // this method would return 0 (https://github.com/zed-industries/community/issues/2422) + // It seems most likely that this would happen if the window has no screen + // (if it is off-screen), though we'd expect to see viewDidChangeBackingProperties before + // it was rendered for real. + // Regardless, attempt to avoid the issue here. + if factor == 0.0 { + 2. + } else { + factor } }