Skip to content

Commit

Permalink
On macOS, fix wry window can crash if unfocused (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
wusyong authored Mar 24, 2023
1 parent 407a9fe commit 6a03847
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/views.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tao": patch
---

On macOS, fix wry window will crash if unfocused.

6 changes: 5 additions & 1 deletion src/platform_impl/macos/window_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ use crate::{

pub struct WindowDelegateState {
ns_window: IdRef, // never changes
// We keep this ns_view because we still need its view state for some extern function
// like didResignKey
ns_view: IdRef, // never changes

window: Weak<UnownedWindow>,

Expand All @@ -60,6 +63,7 @@ impl WindowDelegateState {
let scale_factor = window.scale_factor();
let mut delegate_state = WindowDelegateState {
ns_window: window.ns_window.clone(),
ns_view: window.ns_view.clone(),
window: Arc::downgrade(window),
initial_fullscreen,
previous_position: None,
Expand Down Expand Up @@ -398,7 +402,7 @@ extern "C" fn window_did_resign_key(this: &Object, _: Sel, _: id) {
// Object referenced by state.ns_view (an IdRef, which is dereferenced
// to an id)
let view_state: &mut ViewState = unsafe {
let ns_view: &Object = state.ns_view().as_ref().expect("failed to deref");
let ns_view: &Object = (*state.ns_view).as_ref().expect("failed to deref");
let state_ptr: *mut c_void = *ns_view.get_ivar("taoState");
&mut *(state_ptr as *mut ViewState)
};
Expand Down

0 comments on commit 6a03847

Please sign in to comment.