Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

huacnlee
Copy link
Contributor

@huacnlee huacnlee commented Feb 10, 2025

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 tauri-apps/wry#1383 on Windows can replay the crash.

In fact, we had done a similar fix around August last year, 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.

#[doc(hidden)]
#[track_caller]
pub fn borrow_mut(&self) -> AppRefMut {
if option_env!("TRACK_THREAD_BORROWS").is_some() {
let thread_id = std::thread::current().id();
eprintln!("borrowed {thread_id:?}");
}
AppRefMut(self.app.borrow_mut())
}

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

Copy link

cla-bot bot commented Feb 10, 2025

We require contributors to sign our Contributor License Agreement, and we don't have @sunli829 on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@huacnlee huacnlee changed the title gpui: Fix update_window to borrow_mut will crash on Windows. gpui: Fix update_window to borrow_mut will crash on Windows Feb 10, 2025
@huacnlee
Copy link
Contributor Author

@cla-bot check

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 10, 2025
Copy link

cla-bot bot commented Feb 10, 2025

The cla-bot has been summoned, and re-checked this pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants