Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StandaloneFileBrowserLinux.cs with NullReferenceException #45

Closed
riveranb opened this issue Oct 16, 2018 · 3 comments
Closed

StandaloneFileBrowserLinux.cs with NullReferenceException #45

riveranb opened this issue Oct 16, 2018 · 3 comments

Comments

@riveranb
Copy link

riveranb commented Oct 16, 2018

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
Copy link

rhedgeco commented Nov 2, 2018

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

@riveranb
Copy link
Author

riveranb commented Nov 4, 2018

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
Copy link
Contributor

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.

@gkngkc gkngkc closed this as completed in 65f55d9 Nov 6, 2018
gkngkc added a commit that referenced this issue Nov 6, 2018
github-actions bot pushed a commit to adrenak/usfb that referenced this issue Apr 8, 2020
Generalizes the ways to cancel the window.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants