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
This commit is contained in:
CharlesChen0823
2025-05-15 09:50:58 +02:00
committed by GitHub
parent bba3db9378
commit b2fc4064c0
+6
View File
@@ -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
};