Skip to content

Commit 82eab46

Browse files
authored
macOS: fix a crash when dragging non-file content onto window
Winit only supports text, thus we should ignore the rest instead of crashing.
1 parent a9c189a commit 82eab46

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

winit-appkit/src/window_delegate.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,16 @@ define_class!(
353353
use std::path::PathBuf;
354354

355355
let pb = sender.draggingPasteboard();
356+
356357
#[allow(deprecated)]
357-
let filenames = pb
358-
.propertyListForType(unsafe { NSFilenamesPboardType })
359-
.unwrap()
358+
let property_list = match pb.propertyListForType(unsafe { NSFilenamesPboardType }) {
359+
Some(property_list) => property_list,
360+
None => return false.into(),
361+
};
362+
363+
let paths = property_list
360364
.downcast::<NSArray>()
361-
.unwrap();
362-
let paths = filenames
365+
.unwrap()
363366
.into_iter()
364367
.map(|file| PathBuf::from(file.downcast::<NSString>().unwrap().to_string()))
365368
.collect();
@@ -411,13 +414,16 @@ define_class!(
411414
use std::path::PathBuf;
412415

413416
let pb = sender.draggingPasteboard();
417+
414418
#[allow(deprecated)]
415-
let filenames = pb
416-
.propertyListForType(unsafe { NSFilenamesPboardType })
417-
.unwrap()
419+
let property_list = match pb.propertyListForType(unsafe { NSFilenamesPboardType }) {
420+
Some(property_list) => property_list,
421+
None => return false.into(),
422+
};
423+
424+
let paths = property_list
418425
.downcast::<NSArray>()
419-
.unwrap();
420-
let paths = filenames
426+
.unwrap()
421427
.into_iter()
422428
.map(|file| PathBuf::from(file.downcast::<NSString>().unwrap().to_string()))
423429
.collect();

winit/src/changelog/unreleased.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,4 @@ changelog entry.
272272
- On Web, device events are emitted regardless of cursor type.
273273
- On Wayland, `axis_value120` scroll events now generate `MouseScrollDelta::LineDelta`
274274
- On X11, mouse scroll button events no longer cause duplicated `WindowEvent::MouseWheel` events.
275+
- On macOS, fixed crash when dragging non-file content onto window.

0 commit comments

Comments
 (0)