Commit 9eb6fc0
authored
gpui: Fix RefCell panic in thermal/keyboard state callbacks (#49187)
The `on_thermal_state_change` and `on_keyboard_layout_change` callbacks
in `App::new_app()` called `borrow_mut()` unconditionally. These
callbacks are invoked asynchronously by macOS via dispatch queues when
the system's thermal or keyboard state changes, which can happen while
the app's RefCell is already borrowed during an update cycle, causing a
panic.
This change uses `try_borrow_mut()` instead. If the borrow fails
(because the app is already borrowed), the callback silently skips the
update - the state can be queried on the next frame.
Fixes [ZED-4WM](https://zed-dev.sentry.io/issues/ZED-4WM)
Closes #49181
Release Notes:
- Fixed a crash on macOS caused by thermal or keyboard layout state
changes occurring during UI updates.1 parent d89ee32 commit 9eb6fc0
1 file changed
+16
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
732 | 732 | | |
733 | 733 | | |
734 | 734 | | |
735 | | - | |
736 | | - | |
737 | | - | |
738 | | - | |
739 | | - | |
740 | | - | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
741 | 744 | | |
742 | 745 | | |
743 | 746 | | |
| |||
746 | 749 | | |
747 | 750 | | |
748 | 751 | | |
749 | | - | |
750 | | - | |
751 | | - | |
752 | | - | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
753 | 759 | | |
754 | 760 | | |
755 | 761 | | |
| |||
0 commit comments