macOS: fix crash due during window drop
On macOS 26+ the window drop was leading to unwrap, since events were coming after the window was already destroyed, while it sounds rather strange, guard against such things just in case. Fixes #4333.
This commit is contained in:
parent
bd98561b38
commit
d6f7a28499
2 changed files with 11 additions and 2 deletions
|
|
@ -12,6 +12,7 @@ use objc2_app_kit::{
|
|||
NSApplication, NSCursor, NSEvent, NSEventPhase, NSResponder, NSTextInputClient,
|
||||
NSTrackingRectTag, NSView, NSWindow,
|
||||
};
|
||||
use objc2_core_foundation::CGRect;
|
||||
use objc2_foundation::{
|
||||
NSArray, NSAttributedString, NSAttributedStringKey, NSCopying, NSMutableAttributedString,
|
||||
NSNotFound, NSObject, NSPoint, NSRange, NSRect, NSSize, NSString, NSUInteger,
|
||||
|
|
@ -361,9 +362,16 @@ define_class!(
|
|||
_actual_range: *mut NSRange,
|
||||
) -> NSRect {
|
||||
trace_scope!("firstRectForCharacterRange:actualRange:");
|
||||
|
||||
// Guard when the view is no longer in a window during teardown.
|
||||
let Some(window) = (**self).window() else {
|
||||
return CGRect::ZERO;
|
||||
};
|
||||
|
||||
// Return value is expected to be in screen coordinates, so we need a conversion
|
||||
let rect = NSRect::new(self.ivars().ime_position.get(), self.ivars().ime_size.get());
|
||||
// Return value is expected to be in screen coordinates, so we need a conversion here
|
||||
self.window().convertRectToScreen(self.convertRect_toView(rect, None))
|
||||
let view_rect = self.convertRect_toView(rect, None);
|
||||
window.convertRectToScreen(view_rect)
|
||||
}
|
||||
|
||||
#[unsafe(method(insertText:replacementRange:))]
|
||||
|
|
|
|||
|
|
@ -254,3 +254,4 @@ changelog entry.
|
|||
- On macOS, fixed the scancode conversion for `IntlBackslash`.
|
||||
- On macOS, fixed redundant `SurfaceResized` event at window creation.
|
||||
- On macOS, don't panic on monitors with unknown bit-depths.
|
||||
- On macOS, fixed crash when closing the window on macOS 26+.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue