From b2fc4064c0bfe45435dfc8a54a838d3470446c75 Mon Sep 17 00:00:00 2001 From: CharlesChen0823 Date: Thu, 15 May 2025 15:50:58 +0800 Subject: [PATCH] gpui: Avoid dereferencing null pointer (#30579) as [comments](https://github.com/zed-industries/zed/pull/24545#issuecomment-2872833658), I really don't known why, But IMO, add this code is not harm. If you think this is not necessary, can close. Release Notes: - N/A --- crates/gpui/src/platform/mac/window.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index 26a62aeadfd0b54d417bdff13d786b5baf4e5ccb..c49219bff18dfbdf56b05a37b6cedf7d94ad88a6 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -844,6 +844,9 @@ impl PlatformWindow for MacWindow { fn display(&self) -> Option> { unsafe { let screen = self.0.lock().native_window.screen(); + if screen.is_null() { + return None; + } let device_description: id = msg_send![screen, deviceDescription]; let screen_number: id = NSDictionary::valueForKey_( device_description, @@ -1193,6 +1196,9 @@ impl rwh::HasDisplayHandle for MacWindow { fn get_scale_factor(native_window: id) -> f32 { let factor = unsafe { let screen: id = msg_send![native_window, screen]; + if screen.is_null() { + return 1.0; + } NSScreen::backingScaleFactor(screen) as f32 };