# Call CGGetActiveDisplayList once to avoid panic \(\#4069\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/0bf66e486ab31057043f571a41aebe7106d5ba8d)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 0bf66e486ab31057043f571a41aebe7106d5ba8d

Requested commit: 0bf66e486ab31057043f571a41aebe7106d5ba8d

Commit: 0bf66e486ab31057043f571a41aebe7106d5ba8d

Tree: 528464cc789c6992b7c394cd04cedbcb72a175c8

Author: Thorsten Ball

Committer: GitHub

## Message

````
Call CGGetActiveDisplayList once to avoid panic (#4069)

This contains two changes in order to hopefully avoid the panic we saw
in #panics:

```
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value'
crates/gpui/src/platform/mac/display.rs:30
<backtrace::capture::Backtrace as core::fmt::Debug>::fmt
<backtrace::capture::Backtrace as core::fmt::Debug>::fmt
Zed::init_panic_hook::{closure#0}
std::panicking::rust_panic_with_hook
std::panicking::rust_panic_with_hook
std::sys_common::backtrace::output_filename
<std::panicking::begin_panic_handler::FormatStringPayload as core::panic::PanicPayload>::take_box
core::panicking::panic_fmt
core::panicking::panic
gpui::platform::mac::display::display_bounds_to_native
<gpui::platform::mac::window::MacWindow as gpui::platform::PlatformWindow>::bounds
<gpui::window::WindowContext>::window_bounds_changed
<gpui::window::Window>::new::{closure#1}
gpui::platform::mac::window::view_did_change_backing_properties
<gpui::platform::mac::platform::MacPlatform as gpui::platform::Platform>::run
Zed::main
<core::marker::PhantomData<core::option::Option<Zed::LocationData>> as serde::de::DeserializeSeed>::deserialize::<&mut serde_json::de::Deserializer<serde_json::read::StrRead>>
workspace::open_new::<Zed::restore_or_create_workspace::{closure#0}::{closure#0}::{closure#0}::{closure#2}::{closure#0}>::{closure#0}::{closure#0}
std::rt::lang_start_internal
serde_json::de::from_trait::<serde_json::read::StrRead, core::option::Option<Zed::Panic>>
```

Two changes:
* Reduce the number of calls to `CGGetActiveDisplayList` in the hopes
that this will also reduce chances of it returning an empty list.
Previously, in the worst case, we called it 6 times. Now the worst case
is that we call it 3 times.
* Instead of calling `CGGetActiveDisplayList` to get the primary display
we do what Chromium does and construct the primary display from
NSScreen.

Release Notes:

- Fixed a bug that caused a panic that could happen when Zed attempted
to render on a sleeping display.
````

## Parents

- [ed78f705ebf6f8afa2868ea029d0dd25df7777ee](https://git.cafe/gitcafe/zed/commit/ed78f705ebf6f8afa2868ea029d0dd25df7777ee?format=markdown)

- [f938bae0a2122b5244a19bfef5d3b3b4c1a5335b](https://git.cafe/gitcafe/zed/commit/f938bae0a2122b5244a19bfef5d3b3b4c1a5335b?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/0bf66e486ab31057043f571a41aebe7106d5ba8d?format=markdown)
