Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix window crash (#57203)
Mikayla Maki952119de41c4
diff --git a/crates/gpui/src/app/async_context.rs b/crates/gpui/src/app/async_context.rsindex be917764f43..6c5246f33d0 100644--- a/crates/gpui/src/app/async_context.rs+++ b/crates/gpui/src/app/async_context.rs@@ -378,12 +378,21 @@ impl AppContext for AsyncWindowContext {whereT: 'static,{- // Associate the new entity with our captured window so that- // `with_window` can resolve a dispatch target before the entity has- // been rendered.- self.app- .update_window(self.window, |_, _, cx| cx.new(build_entity))- .expect("window was unexpectedly closed")+ let mut build_entity = Some(build_entity);+ match self.app.update_window(self.window, |_, _, cx| {+ cx.new(+ build_entity+ .take()+ .expect("build_entity is taken exactly once"),+ )+ }) {+ Ok(entity) => entity,+ Err(_) => self.app.new(+ build_entity+ .take()+ .expect("update_window returned Err without invoking the closure"),+ ),+ }}fn reserve_entity<T: 'static>(&mut self) -> Reservation<T> {@@ -395,11 +404,19 @@ impl AppContext for AsyncWindowContext {reservation: Reservation<T>,build_entity: impl FnOnce(&mut Context<T>) -> T,) -> Entity<T> {- self.app- .update_window(self.window, |_, _, cx| {- cx.insert_entity(reservation, build_entity)- })- .expect("window was unexpectedly closed")+ let mut args = Some((reservation, build_entity));+ match self.app.update_window(self.window, |_, _, cx| {+ let (reservation, build_entity) = args.take().expect("args are taken exactly once");+ cx.insert_entity(reservation, build_entity)+ }) {+ Ok(entity) => entity,+ Err(_) => {+ let (reservation, build_entity) = args+ .take()+ .expect("update_window returned Err without invoking the closure");+ self.app.insert_entity(reservation, build_entity)+ }+ }}fn update_entity<T: 'static, R>(