macOS: fix a crash when dragging non-file content onto window

Winit only supports text, thus we should ignore the rest
instead of crashing.
This commit is contained in:
Dan Harris
2025-11-04 20:20:01 -08:00
committed by Kirill Chibisov
parent f6893a4390
commit ab4c6bfc82
2 changed files with 9 additions and 3 deletions

View File

@@ -42,4 +42,4 @@ changelog entry.
### Fixed
- On macOS, fix crash on macOS 26 by using objc2's `relax-sign-encoding` feature.
- On macOS, fixed crash when dragging non-file content onto window.

View File

@@ -373,7 +373,10 @@ declare_class!(
use std::path::PathBuf;
let pb: Retained<NSPasteboard> = unsafe { msg_send_id![sender, draggingPasteboard] };
let filenames = pb.propertyListForType(unsafe { NSFilenamesPboardType }).unwrap();
let filenames = match pb.propertyListForType(unsafe { NSFilenamesPboardType }) {
Some(filenames) => filenames,
None => return false.into(),
};
let filenames: Retained<NSArray<NSString>> = unsafe { Retained::cast(filenames) };
filenames.into_iter().for_each(|file| {
@@ -399,7 +402,10 @@ declare_class!(
use std::path::PathBuf;
let pb: Retained<NSPasteboard> = unsafe { msg_send_id![sender, draggingPasteboard] };
let filenames = pb.propertyListForType(unsafe { NSFilenamesPboardType }).unwrap();
let filenames = match pb.propertyListForType(unsafe { NSFilenamesPboardType }) {
Some(filenames) => filenames,
None => return false.into(),
};
let filenames: Retained<NSArray<NSString>> = unsafe { Retained::cast(filenames) };
filenames.into_iter().for_each(|file| {