xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.46k stars 512 forks source link

NSOpenPanel crash if an event handler is attached for DidChangeToDirectory #7366

Open Therzok opened 4 years ago

Therzok commented 4 years ago

Steps to Reproduce

  1. See sample code below
  2. Click the button and search in the NSOpenPanel search field until you have no entries
  3. Native crash

Expected Behavior

No crash.

Actual Behavior

The code crashes because it tries to marshal NSNull as NSUrl. Modifying the static registrar manually to check for the value being NSNull fixes the crash.

Environment

=== Visual Studio Enterprise 2019 for Mac (Preview) === Version 8.6 Preview (8.6 build 210) Installation UUID: 010a6a17-65d7-44f0-9e3d-48e5afe82e81 GTK+ 2.24.23 (Raleigh theme) Xamarin.Mac 6.8.1.1 (d16-4 / 2e360ee4) Package version: 606000148 === Mono Framework MDK === Runtime: Mono 6.6.0.148 (2019-08/6ac1ff75a27) (64-bit) Package version: 606000148 === Roslyn (Language Service) === 3.4.0-beta3-19518-02+7c7708ed32437b99ab18a21d056d7ae0949e8d5c === NuGet === Version: 5.3.0.6192 === .NET Core SDK === SDK: /usr/local/share/dotnet/sdk/3.1.100-preview2-014569/Sdks SDK Versions: 3.1.100-preview2-014569 3.1.100-preview1-014459 3.0.100 2.2.203 MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.6.0/lib/mono/msbuild/Current/bin/Sdks === .NET Core Runtime === Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 3.1.0-preview2.19525.6 3.1.0-preview1.19506.1 3.0.0 3.0.0-rc1-19456-20 3.0.0-preview9-19423-09 3.0.0-preview6-27804-01 2.2.7 2.2.4 2.1.13 2.1.12 2.1.11 2.1.10 === Xamarin.Profiler === '/Applications/Xamarin Profiler.app' not found === Updater === Version: 11 === Apple Developer Tools === Xcode 11.2 (15526) Build 11B52 === Xamarin.Mac === Version: 6.8.1.1 (Visual Studio Enterprise) Hash: 2e360ee4 Branch: d16-4 Build date: 2019-10-08 09:18:27-0400 === Xamarin.iOS === Version: 13.8.1.1 (Visual Studio Enterprise) Hash: 2e360ee4 Branch: d16-4 Build date: 2019-10-08 09:18:28-0400 === Xamarin Designer === Version: 16.4.0.436 Hash: 5048057c4 Branch: remotes/origin/d16-4 Build date: 2019-10-18 01:57:50 UTC === Xamarin.Android === Version: 10.1.0.12 (Visual Studio Enterprise) Commit: monodroid/HEAD/9ff00e53a Android SDK: /Users/therzok/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 4.4 (API level 19) 4.4.87 (API level 20) 5.0 (API level 21) 5.1 (API level 22) 6.0 (API level 23) 7.0 (API level 24) 7.1 (API level 25) 8.0 (API level 26) 8.1 (API level 27) SDK Tools Version: 26.1.1 SDK Platform Tools Version: 28.0.0 SDK Build Tools Version: 27.0.0 Build Information: Mono: d8441de Java.Interop: xamarin/java.interop/d16-4@35b08ba ProGuard: xamarin/proguard/master@905836d SQLite: xamarin/sqlite/3.28.0@46204c4 Xamarin.Android Tools: xamarin/xamarin-android-tools/master@9f4ed4b === Microsoft Mobile OpenJDK === Java SDK: /Users/therzok/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25 1.8.0-25 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL === Android SDK Manager === Version: 1.4.0.47 Hash: 105efbb Branch: remotes/origin/joj/updatemanifesturl~1 Build date: 2019-10-15 18:03:28 UTC === Android Device Manager === Version: 1.2.0.132 Hash: c79f4b5 Branch: remotes/origin/a11y/982173-property-vo-focus~5 Build date: 2019-10-15 18:03:50 UTC === Xamarin Inspector === Version: 1.4.3 Hash: db27525 Branch: 1.4-release Build date: Mon, 09 Jul 2018 21:20:18 GMT Client compatibility: 1 === Build Information === Release ID: 806000210 Git revision: 3e1e14b604d6857ebbe321df8f62d5439c296694 Build date: 2019-11-05 16:37:43+02 Xamarin extensions: f32291eeff28b4dd7c5cedfeb685927807a3dd62 === Operating System === Mac OS X 10.15.1 Darwin 19.0.0 Darwin Kernel Version 19.0.0 Thu Oct 17 16:17:15 PDT 2019 root:xnu-6153.41.3~29/RELEASE_X86_64 x86_64 === Enabled user installed extensions === Log Monitor 0.2 AddinMaker 1.6.0

Example Project (If Possible)

Add this to the template ViewController.ViewDidLoad:

var panel = new NSSavePanel();
panel.DidChangeToDirectory += (o, args) => {
    var url = args.NewDirectoryUrl;
    Console.WriteLine(url.Path);
};

View.AddSubview(NSButton.CreateButton("a", () => panel.RunModal()));
rolfbjarne commented 4 years ago

A potential workaround is to use the delegate pattern instead of the event pattern, and declare the DidChangeToDirectory function with more encompassing signature: https://github.com/rolfbjarne/mactestapp/blob/2251988eeb75c6f7a8c0e9dfc1694f964bc90a57/mactestapp/ViewController.cs#L36

rolfbjarne commented 4 years ago

Apple feedback: https://github.com/xamarin/maccore/issues/2051 (FB7428536)