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

Opening the File Chooser on Linux instantly crashes the player #33

Closed
xeruf opened this issue Jan 25, 2018 · 41 comments
Closed

Opening the File Chooser on Linux instantly crashes the player #33

xeruf opened this issue Jan 25, 2018 · 41 comments
Assignees
Labels
bug unexpected malfunction

Comments

@xeruf
Copy link
Collaborator

xeruf commented Jan 25, 2018

It opens a blank file chooser window and then instantly crashes. The issue seems to lie in JNA.
hs_err_pid12804.log

@xeruf xeruf added this to the Linux milestone Jan 25, 2018
@sghpjuikit
Copy link
Owner

sghpjuikit commented Jan 25, 2018

How did you come to the conclusion that JNA is related to this?

I'd like for you to make a very simple JavaFX application/demo that opens a standard JavaFX File dialog and see it the problem persists. The file chooser should just work.

Please see this:
https://stackoverflow.com/questions/44995070/jvm-crashes-on-ubuntu-trying-to-open-javafx-save-dialog-or-open-dialog
https://usn.ubuntu.com/usn/usn-3345-1/

@xeruf xeruf added the bug unexpected malfunction label Jan 31, 2018
@xeruf
Copy link
Collaborator Author

xeruf commented Jan 31, 2018

A directory chooser I tested worked without issue, but I will investigate further.
This screenshot shows how it looks for literally a splitsecond before the crash:

@sghpjuikit
Copy link
Owner

sghpjuikit commented Feb 1, 2018

Thx for the report. This could be related to extension filters (audio) passed into the chooser.

I will try setting up a Linux VM to reproduce and fix the issue.

@sghpjuikit
Copy link
Owner

sghpjuikit commented Feb 5, 2018

This may be a bug on your side. I'm running VM with Linux Mint using Vmware on Windows and I am able to open both directory and file chooser.

I'm running

  • (latest official) Linux Mint 18.3 Sylvia
  • on OracleJDK 9.0.4+11
  • I launched the application manually (no IDE, no script) from working directory with command like ./jre/bin/java -cp '.:PlayerFX:lib/*" sp.it.pl.main.AppUtil (I havent included the add opens arguments here...)

@sghpjuikit
Copy link
Owner

Because I can not reproduce this I can not test workarounds.

One possible cause I can imagine is the extension filter. Please see Environment.class and chooseFile/chooseFiles methods and remove the line setting the extensions: this.extensionFilters += extensions.

@xeruf
Copy link
Collaborator Author

xeruf commented Feb 7, 2018

wait how does the application work without the add-opens?

I'll test your suggestion when I get back to my PC

@xeruf xeruf self-assigned this Feb 7, 2018
@sghpjuikit
Copy link
Owner

I havent included the add-opens here for brevity. I have included it in the launch command.

@xeruf
Copy link
Collaborator Author

xeruf commented Feb 13, 2018

nope, removing the extensionfilters still didn't work

@sghpjuikit
Copy link
Owner

This may be a threading issue (Javafx vs Swing), one of the FileChooser parameters, JDK bug or OS bug. I will continue to try to reproduce the behavior, but until then you can try to eliminate possibilities. For example, what happens if you open some FileChooser in the App.init() or App.start() method? And so on.

@xeruf
Copy link
Collaborator Author

xeruf commented Mar 1, 2018

at least I can drag in songs as a workaround ^^

xeruf pushed a commit that referenced this issue Mar 2, 2018
* set isGlobalShortcutsSupported to false for Unix
* fix missing checks for isGlobalShortcutsSupported

fixes #33
@xeruf xeruf closed this as completed Mar 3, 2018
@sghpjuikit
Copy link
Owner

I'm opening this as the solution is only a workaround.

@sghpjuikit
Copy link
Owner

sghpjuikit commented Dec 31, 2018

Is this issue back? I think the final fix targeted lazy initialization of jnativehook library.

@sghpjuikit sghpjuikit reopened this Dec 31, 2018
@xeruf
Copy link
Collaborator Author

xeruf commented Dec 31, 2018

Hmpf... I'll look into it later ^^

@sghpjuikit
Copy link
Owner

I coincidentally found a bug report on JavaFX11 crashing on Linux with Wayland due to gtk3 or something.
But first try isolating jnativehook, since it is the primary suspect. Classes are ActionManager and Hotkeys. The library must not load. Just a heads up since we already confirmed it loads eagerly and unpredictably in a static initialization block.

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 1, 2019

I have Xorg though, not Wayland. Let's see...

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 8, 2019

I have created a little test project with JNativeHook 2.1.0 in which I called GlobalScreen.registerNativeHook(), launched the application and showed a file chooser. No problems...

@sghpjuikit
Copy link
Owner

I know this issue must be quite annoying, but I am unable to reproduce it. I will give it another shot.

Pls try removing the library altogether and make Hotkeys just do nothing and test the behavior.

@sghpjuikit
Copy link
Owner

I think I may have figured this out. Please try removing lines 27-31 from Hotkeys.class. The code that silences the logger:

    constructor(executor: (Runnable) -> Unit) {
        this.executor = executor

        // Disable library logging.
         java.util.logging.Logger.getLogger(GlobalScreen::class.java.getPackage().name).apply {
             level = java.util.logging.Level.OFF
             useParentHandlers = false
         }
    }

I think that GlobalScreen::class.java.getPackage() triggers GlobalScreen class initialization. I moved this code from start() to constructor, in hopes of removing some of the undesirable library logging.

PS: version 2.1.0 removes some of the undesirable output. If this fix works, could you try if 2.1.0 is unusable? All I know is what the comment in build script says: that 2.1.0 causes critical issue on Linux.

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 9, 2019

All I know is what the comment in build script says: that 2.1.0 causes critical issue on Linux.

Yes, because that is true. There have been a few reports which point a particular library that it uses since 2.1.
I have also submitted a PR, let's see how he reacts: kwhat/jnativehook#251

I will try what you've suggested, sounds like a good pointer.

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 9, 2019

Found the culprit: isGlobalShortcutsSupported is true by default, on every OS. Didn't we set this to be false on Linux?

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 9, 2019

version 2.1.0 removes some of the undesirable output

Not really. I have done a test with 2.1 and the spam is still insane.

@sghpjuikit
Copy link
Owner

But if the library is not used, it does not cause an issue right? SO isnt it safe to use 2.1.0?

Not exactly. In my testing I confirmed global shortcuts to work on my Linux Mint. Hence global shortcuts on Linux are supported. However due to potential problems on some systems, we set global shortcuts to be disabled on Linux by default. Everything looks good and unless you changed your settings, the library should not load. You should have the following default values on your system:
Global shortcuts supported: true
Global shortcuts enabled: false

2.1.0 removes the licence header and some other things. The logging suppression still needs to be there, but then there is no visible output at all. That is why I'd prefer to use 2.1.0.

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 9, 2019

Hah, jnativehook isn't the culprit apparently! I have removed it and JNA completely from the application and the filechooser still crashes...

The problem was that Hotkeys shouldn't even have been initialized. But when shortcuts are enabled but not supported, ActionManager calls stopGlobalListening which calls hotkeys.stop which initializes Hotkeys. Anyways, time to find the actual culprit.

@sghpjuikit
Copy link
Owner

"But when shortcuts are enabled but not supported, ActionManager calls stopGlobalListening which calls hotkeys.stop which initializes Hotkeys. "
I see. I'm going to fix this behavior right away is that ok?

"The problem was that Hotkeys shouldn't even have been initialized"
How is that a problem when jnativehook/hotkeys do not cause the trouble for you? It may not be correct, but it is not a problem right?

"jnativehook isn't the culprit apparently!"
All the more reason to test 2.1.0, can you pls do that after I fix the initialization?
If jnativehook isnt doing this then it must be other native library.

Pls try removing Comet widget. It contains native libs for gamepad (gamepad4j-uberjar-0.2.jar, gamepad4j-api-0.2-javadoc.jar).
Also try removing Terminal widget as terminalfx-1.3.jar may contain native stuff too.

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 9, 2019

I see. I'm going to fix this behavior right away is that ok?

I have created a Hotkeys branch to fix this whole stuff, will push it soon. How do you want to fix that?

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 9, 2019

How is that a problem when jnativehook/hotkeys do not cause the trouble for you? It may not be correct, but it is not a problem right?

But if it were, it would have been bad. It is not a problem right now, but jnativehook seems to me a pretty unstable thing, who knows if it breaks something again.

All the more reason to test 2.1.0, can you pls do that after I fix the initialization?

I will

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 9, 2019

Okay, removing terminal and comet widget didn't suffice, but I just removed all widgets except configurator and dirViewer and it worked! Now I'll try to isolate the widget at fault here...

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 9, 2019

btw, please prefix text with > for quoting instead of using quotes, it highlights the text properly.

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 9, 2019

Now it just works without problems in master. What the heck. I will reopen if it returns.

@xeruf xeruf closed this as completed Jan 9, 2019
@sghpjuikit
Copy link
Owner

Ok, pls push the hotkey branch, I have fixed numerous issues with hotkeys. Currently testing.

The fix involves testing whether hotkeys variable is initialized. It is lazy and as such it is possible to do hotkeys.orNull()?.unregister which is using the lazy value lazily - i.e., does not trigger initialization. However there were other problems as well as utter chaos in the Action registering code.

Indeed jnativehook is pretty dangerous to use, particularly on Linux, although it causes major problems for me on Windows as well.

I'm very glad you managed to isolate the problem.

  • The next candidate would be WebReader. WebReader uses javaFX' WebView which probably uses quite a lot of native stuff behind the curtains. Could this be a bug in JDK?
  • The only other widget that uses any kind of library is Voronoi. It uses jts (java transformation suite (geometry), just like Comet, so you may try removing these two.
  • The next candidate is Logger, but unlikely. I can not imagine the problem originating from other widget.

@sghpjuikit
Copy link
Owner

Now it just works without problems in master. What the heck. I will reopen if it returns.

The issue did not suddenly go away. Pls try to reproduce it if possible. Is it possible for some native library to get unloaded later on its own? Perhaps you cleared user data? I am not aware of any relevant changes in master branch.

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 9, 2019

It may also be related to my system. I can soon test it on my computer at home to see if it is related to the player or the system.

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 9, 2019

Whenever I was debugging, I used clean run, so it is unlikely to be related to cache/data

@sghpjuikit
Copy link
Owner

I noticed you modified clean to delete user/tmp directory. May be related.

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 9, 2019

No, I modified it to delete lib. But since I now have all libs back again since it just somehow works, this doesn't make a difference either.

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 9, 2019

Oh great, I wanted to test it on my home pc, but it doesn't have Java 10, you can't download it since it's end of life, and supporting JDK 11 needs OpenJFX. Back to trying to make openjfx work...

@sghpjuikit
Copy link
Owner

You added this line to clean task:
dirWorking/"user"/"tmp",
This deletes user temp directory, which contains some of the loaded native libraries, including jnativehook, imageio, jna, terminalfx.

I find it hard to believe you can not download Java 10. Do not use Oracle, but OpenJDK? Dunno.

I noticed you started playing around with JDK11, but I'm afraid it will open more then few can of worms with jigsaw, forced modularity, backward incompatible changes in Java APIs, more internal API's hidden as well as JavaFX. If you do make it work - great, but do not waste much time, we can work on 10 at least until 12.

@xeruf
Copy link
Collaborator Author

xeruf commented Jan 10, 2019

  1. This line has been in clean task for a very long time. If you are referring to the hotkeys branch, then look again.
  2. OpenJDK doesn't have JavaFX either.
  3. No, no worms. It works without problems, see my PR.

@sghpjuikit
Copy link
Owner

1 I saw the + sign in the commit so I assumed. Ok.

2 Right. Then I guess there's is an installation floating around somewhere.

@sghpjuikit
Copy link
Owner

The actual culprit behind this issue may be vlcj. See caprica/vlcj#834
I am about to push vlcj4, which has a fix for this. Hopefully this will be completely gone now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected malfunction
Projects
None yet
Development

No branches or pull requests

2 participants