gpui: Avoid dereferencing null pointer (#30579)

CharlesChen0823 created

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

Change summary

crates/gpui/src/platform/mac/window.rs | 6 ++++++
1 file changed, 6 insertions(+)

Detailed changes

crates/gpui/src/platform/mac/window.rs 🔗

@@ -844,6 +844,9 @@ impl PlatformWindow for MacWindow {
     fn display(&self) -> Option<Rc<dyn PlatformDisplay>> {
         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
     };