gkngkc / UnityStandaloneFileBrowser

A native file browser for unity standalone platforms
MIT License
2.01k stars 317 forks source link

StandaloneFileBrowserLinux.cs with NullReferenceException #45

Closed riveranb closed 5 years ago

riveranb commented 5 years ago

When using StandaloneFileBrowser in Linux OS (ubuntu), if I choose "CANCEL" or "ESC" in file browse dialog, the returned (string[])paths become null. And will become NullReferenceException at paths.Split(...);

TO FIX, I suggest:

` public string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect) { var paths = Marshal.PtrToStringAnsi(DialogOpenFilePanel( title, directory, GetFilterFromFileExtensionList(extensions), multiselect));

        // debug NullReferenceException
        if (string.IsNullOrEmpty(paths))
        {
            return null;
        }

        return paths.Split((char)28);
    }`

` public string[] OpenFolderPanel(string title, string directory, bool multiselect) { var paths = Marshal.PtrToStringAnsi(DialogOpenFolderPanel( title, directory, multiselect));

        // debug NullReferenceException
        if (string.IsNullOrEmpty(paths))
        {
            return new string[0];
        }

        return paths.Split((char)28);
    }`
rhedgeco commented 5 years ago

If it returns null, it will not ever reach that second return statement. I think your problem lies somewhere else.

riveranb commented 5 years ago

NullReferenceException happens at StandaloneFileBrowserLinux.cs, line 45 and line 63, return paths.Split((char)28);

Because paths is null, So I just try to avoid NullReferenceException in my use cases.

RicardoEPRodrigues commented 5 years ago

I could not find the null error when pressing CANCEL, but I did find it when pressing X. It appears they are different events on GTK.

I made a patch and will make a pull request soon.