# gpui: Fix \`update_window\` to \`borrow_mut\` will crash on Windows \(\#24545\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 0fa9f053131c66f9abdece4e710b67dfa549c497

Requested commit: 0fa9f053131c66f9abdece4e710b67dfa549c497

Commit: 0fa9f053131c66f9abdece4e710b67dfa549c497

Tree: 53743cf75e1c6b8432d03f7a7130a1ec922aecb8

Author: Jason Lee

Committer: GitHub

## Message

````
gpui: Fix `update_window` to `borrow_mut` will crash on Windows (#24545)

Release Notes:

- N/A

---


When we use `window_handle` to draw WebView on Windows, this will crash
by:

This error caused by when used WebView2.

```
thread 'main' panicked at crates\gpui\src\app\async_context.rs:91:28:
already borrowed: BorrowMutError
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at library\core\src\panicking.rs:221:5:
panic in a function that cannot unwind
```

Try this https://github.com/tauri-apps/wry/pull/1383 on Windows can
replay the crash.

In fact, we had done [a similar fix around August last
year](https://github.com/huacnlee/zed/pull/6), but we used the unsafe
method to avoid crashes in that version, we felt that it was not a good
change, so we do not make PR.

Today @sunli829 thought about it again and changed the method. Now using
`try_borrow_mut` is similar to the previous `borrow_mut`.


https://github.com/zed-industries/zed/blob/691de6b4b36d3ada91a1e238904b065eec454188/crates/gpui/src/app.rs#L70-L78

I have tested to start Zed by those changes, it is looks no problem.

Co-authored-by: Sunli <scott_s829@163.com>
````

## Parents

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

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