From ab4c6bfc82686c4cb7bfec639b5b28cdc5b2c81f Mon Sep 17 00:00:00 2001 From: Dan Harris Date: Tue, 4 Nov 2025 20:20:01 -0800 Subject: [PATCH] macOS: fix a crash when dragging non-file content onto window Winit only supports text, thus we should ignore the rest instead of crashing. --- src/changelog/unreleased.md | 2 +- src/platform_impl/macos/window_delegate.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index a7ec5f0ac..eee5740d8 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -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. diff --git a/src/platform_impl/macos/window_delegate.rs b/src/platform_impl/macos/window_delegate.rs index e0dc693c5..e293505eb 100644 --- a/src/platform_impl/macos/window_delegate.rs +++ b/src/platform_impl/macos/window_delegate.rs @@ -373,7 +373,10 @@ declare_class!( use std::path::PathBuf; let pb: Retained = 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> = unsafe { Retained::cast(filenames) }; filenames.into_iter().for_each(|file| { @@ -399,7 +402,10 @@ declare_class!( use std::path::PathBuf; let pb: Retained = 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> = unsafe { Retained::cast(filenames) }; filenames.into_iter().for_each(|file| {