Skip to content

Commit 3e12973

Browse files
authored
avoid crash when window is null in become_first_responder (#204)
* avoid crashing when window is null in become_first_responder * temporarily allow "unexpected_cfgs" on macOS * allow "unexpected_cfgs" in macOS OpenGL code
1 parent 9a0b42c commit 3e12973

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/gl/macos.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// This is required because the objc crate is causing a lot of warnings: https://github.com/SSheldon/rust-objc/issues/125
2+
// Eventually we should migrate to the objc2 crate and remove this.
3+
#![allow(unexpected_cfgs)]
4+
15
use std::ffi::c_void;
26
use std::str::FromStr;
37

src/macos/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// This is required because the objc crate is causing a lot of warnings: https://github.com/SSheldon/rust-objc/issues/125
2+
// Eventually we should migrate to the objc2 crate and remove this.
3+
#![allow(unexpected_cfgs)]
4+
15
mod keyboard;
26
mod view;
37
mod window;

src/macos/view.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,12 @@ extern "C" fn become_first_responder(this: &Object, _sel: Sel) -> BOOL {
245245
let state = unsafe { WindowState::from_view(this) };
246246
let is_key_window = unsafe {
247247
let window: id = msg_send![this, window];
248-
let is_key_window: BOOL = msg_send![window, isKeyWindow];
249-
is_key_window == YES
248+
if window != nil {
249+
let is_key_window: BOOL = msg_send![window, isKeyWindow];
250+
is_key_window == YES
251+
} else {
252+
false
253+
}
250254
};
251255
if is_key_window {
252256
state.trigger_deferrable_event(Event::Window(WindowEvent::Focused));

0 commit comments

Comments
 (0)