java fx jvm crash - java

I have a swing application and inside i added a JFXpanel from javafx2 jdk1.7_17 (also tried 1.7_15). i do create the JFXpanel in EDT and add it on swing tabbed pane, then add the scene to the FXPanel in javaFX thread as shown in the doc. If i run the application once everything is fine, if i stop the application and run it again the jvm crashes saying Problematic Frame libdbus. After closing the application no matter how many times i try the jvm will crash complaining about dbus usually but not always:
JRE version: 7.0_17-b02
Java VM: Java HotSpot(TM) 64-Bit Server VM (23.7-b01 mixed mode linux-amd64 compressed oops)
Problematic frame:
C [libc.so.6+0x12fbd6]Java Result: 134
Sometimes i get this:
GConf-WARNING **: Got Disconnected from DBus.
If i restart the pc it runs ok the first time again and then if i close / re-run it keeps crashing at start up. I am running fedora 18 and i believe it maybe OS related since java FX is using native libs.
FXPanelJob fxPanelJob = new FXPanelJob(fxPanel);
tabbedPane = new JTabbedPane();
tabbedPane.addTab("table", fxPanel);
Platform.runLater(fxPanelJob);
private class FXPanelJob implements Runnable {
private JFXPanel fxPanel;
private volatile boolean done = false;
public FXPanelJob(JFXPanel fxPanel) {
this.fxPanel = fxPanel;
}
#Override
public void run() {
initFX(fxPanel);
done = true;
}
private void initFX(JFXPanel fxPanel) {
// This method is invoked on the JavaFX thread
VBox vbox = new VBox();
Scene scene = new Scene(vbox, 300, 200);
TableView<ReportRaw> table = new Table();
vbox.getChildren().addAll(table);
VBox.setVgrow(table, Priority.ALWAYS);
fxPanel.setScene(scene);
}
}
Since the first time is running i just guessed that might be a problem with shutting down the javafx on application exit. On windowClosing event i have:
Platform.runLater(new Runnable(){ public void run(){
Platform.exit();
});
Update:
It turns out its not a java fx problem, i switched to JDK 6 and everything is fine. I think it is specific to OS problem. Using jdk 7 without java fx could still trigger jvm crash.
if anyone knows what might be causing the jvm to crash i would appreciate.
Thank you in advance
Update 2
found a similar post, it seems to have been solved but i am not sure:
http://ubuntuforums.org/showthread.php?t=1697231&page=3
use this for jvm arguement -XX:-UseCompressedOops. i'll post it as an answer when i make sure its not crashing anymore.
Update 3
Couldn't solve it i commented out my javafx code as a solution. I believe its EDT related but i cant guarantee. it seems to be occuring several lines after the JavaFx panel is added on swing app. Not always at the same line. If removed everything works, so i guess its still an immature project.

Related

Java crashes when creating a JFrame

I am baffled at this issue. I just wanted to create a JFrame for testing, this is the only class:
import javax.swing.*;
public class TextPaneTest extends JFrame {
public TextPaneTest(){
setTitle("Test");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setSize(200, 200);
setVisible(true);
}
public static void main(String[] args){
new TextPaneTest();
}
}
I am using IntelliJ IDEA 2019.2.4 as my IDE.
The result is a small white JFrame opens up for 2 seconds and closes. You can't move or resize the window and the cursor remains in "wait" mode when you hover the frame.
This is my project structure:
And this is my run configuration:
There is no error message or exception. All the console shows is:
Process finished with exit code -1073740771 (0xC000041D)
I've already done a clean reinstall of both the JRE and JDK
This is my current java -version:
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
My OS is Windows 10 Home Single Language 1903
I don't know what else to add. I've been using Java for the past 5 years as a hobbyist and I've never came across an issue so fundamental as this.
Update
Tried instantiating TextPaneTest() using SwingUtilities.invokeLater()
Tried building the JAR and running from a command window
None has worked so far. Exactly the same behaviour.
Update 2
Fixed it by switching the 64 bit JRE for the 32 one. Is this a bug with the 64 one or could there be an underlying problem?
I cannot reproduce the issue on my macintosh, but I notice you are doing everything on the main thread. You shouldn't do that. Make sure all events happen on the Event Dispatch Thread. For example,
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new TextPaneTest();
}
});
}

JavaFX native packaging - bizarre error with initialising static variables

I'm working on a JavaFX project in Netbeans that's currently around 3000 lines long, and I've packaged as an .exe regularly for testing but never come across an issue like this curious incident.
When packaging natively as a Windows .exe file, I found that after installing the .exe and launching my program I was getting a popup saying "Class {mypackage}/{mymainclass} not found." followed by "Failed to launch JVM."
Launching the program in Netbeans, packaging as an .exe, and launching the .jar in Powershell with "java -jar {app}.jar" all gave absolutely no errors. Even the .jar inside the installed application folder was fine, with no errors on the command line.
After a few hours of trawling through git commits and packaging natively, I managed to trace the issue down to a single line of code:
private static ComboBox choices = new ComboBox();
When I initialise the ComboBox in an initialiser, the program magically works after being installed from an .exe:
private static ComboBox choices;
{
choices = new ComboBox();
}
However, when I use a static initialiser (by placing static in front of the first curly brace), even though Netbeans states "initialiser can be static", I get the same error as before.
This is puzzling, because Java is obviously fine with the code itself, but after it's been through the native packager it will not launch. I've used plenty of similar lines of code to initialise static variables in other classes, with no ill effects.
I tried adding a similar line to the main class: private static CheckBox chkbox = new CheckBox();
It caused the exact same error after the .exe was installed (as before, the .jar was fine), but when I cut-and-pasted the line to a different class, it had no effect.
Interestingly, my main class already has a static boolean that is initialised in the same way that the ComboBox and CheckBox were: private static boolean someBool = true; but the boolean causes no problems.
Can anyone explain the reason behind this? Thank you.
Edit: I also tried packaging on a different machine, but it stopped working after the same git commit.
I'm using version 1.8.0_144 of the JDK and JRE.
Edit 2: here is the main class of a simple example that produces the error.
package testproject;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.CheckBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class MainApplication extends Application {
private static CheckBox testCheckBox = new CheckBox(); // Causes error after launching from installed .exe
/* UNCOMMENT THIS SECTION AND REMOVE THE " = new CheckBox()" ABOVE TO FIX THE ERROR
{
testCheckBox = new CheckBox();
}
*/
#Override
public void start(Stage primaryStage) {
StackPane root = new StackPane();
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Empty window");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I would avoid creating JavaFX widgets in static initializers (such as a static field or static block), as this would create them when class is loaded, which might happen in any thread. You want that to happen in JavaFX Application Thread.
In your case it happens in main thread, which is definitely not correct.
Check this answer for more details about JavaFX application startup, and how threads are involved in the process.
Trying to initialize a JavaFX widget outside of "JavaFX Application Thread" is (to my understanding) undefined behavior, and might fail in many different ways (or succeed by luck). If that creation fails, then the class loading fails (because static init has failed), hence "class not found". Unfortunately, since this happens while loading main class, you don't get to see the initial error, just "class XXX not found".
Possibly in your case, the java launcher can deal with this initialization just fine, but the launcher used by your .exe is different. I'm not too surprised it fails. I'm equally surprised it works with regular java :)

JavaFX MediaPlayer exceptions in Debian Linux

I'm having issues (like some others) with getting the JavaFX MediaPlayer component to play content (video/audio files of any container/encoding type) in Debian Jessie. I've tried and exhausted any potential solution to this problem (I have GLIB 2.28 installed, I've upgraded Java to u60, I've ensured all codec packages have been installed including libavcodec/libavformat/libavutil/etc., I'm at gtk2 2.18+). I don't know what else to do or try. I have a very simple application that works perfectly fine under Windows 7.
Here is the simple application:
public class MediaTest extends Application {
#Override
public void start(Stage primaryStage) {
BorderPane root = new BorderPane();
Media media = new Media(new File("/path/to/file/test.flv").toURI().toString());
MediaPlayer player = new MediaPlayer(media);
MediaView view = new MediaView(player);
root.setCenter(view);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("For the love of God, please work");
primaryStage.setScene(scene);
primaryStage.show();
player.play();
}
public static void main(String[] args) {
launch(args);
}
}
The problem manifests on the creation of the MediaPlayer. After a few lengthy debugging sessions, I found that the exception that is internally generated is some permutation of MEDIA_UNSUPPORTED message, regardless of the media type or format, though the Exception that is caught lists it as
MediaException: UNKNOWN : com.sun.media.jfxmedia.MediaException: Could not create player!
I've tried just about everything I can think of. I have a sample video file encoded just about every way possible, and in a myriad of different containers. Nothing works. I have a sample audio file encoded in just about every way possible, with the same results.
Am I just SOL on getting MediaPlayer to work on Debian? If so, this is highly disappointing. I know it's nigh impossible to get something to work on Windows, Mac, and every distro of Linux, but Write Once Run Everywhere seems not to hold true for Java8.
EDIT: I have oracle's java8, not openjdk.
EDIT 2: The internal error seems to be coming from gstreamer.
Here are the args going into MediaException.getMediaException(Object source, int errorCode, String message):
source : com.sun.media.jfxmediaimpl.platform.gstreamer.GSTMedia
errorCode : 265
message : ERROR_MEDIA_AUDIO_FORMAT_UNSUPPORTED
Mind the graphics drivers. For example, in Ubuntu 16.04, the AMD opensource graphics drivers seem incomplete, javafx video seems impossible.
I got it to work in this environment:
Ubuntu 14.04, intel chipset graphics, oracle jdk 8.
Installed libavcodec54 and libavformat54. Not it works (Graphics and sound OK). My test video: http://www.sample-videos.com/video/flv/720/big_buck_bunny_720p_1mb.flv
(container: MP4/M4a, video: H.264, sound: MPEG-4 AAC)

Java error: "Can't open input server /Library/InputManagers/Inquisitor"

I'm just now getting into GUI's in Java and when experimenting with JFrame I get the following error:
java[3126:71534] Can't open input server /Library/InputManagers/Inquisitor
Despite the error the program runs fine, but I'd like to know what this is about as I couldn't find much about Inquisitor anywhere.
Running Netbeans 8.0.2 and Java 8 Update 40 on OS X Yosemite (10.10.2). The java code being run is:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Ikkuna extends JFrame implements ActionListener{
JTextField syöte;
JLabel vastaus;
JButton painike;
public void setTitle(String string){
super.setTitle(string);
}
public Ikkuna(){
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setTitle("Celsius / Fahrenheit -muunnos");
this.setSize(400, 200);
this.setResizable(false);
JPanel paneeli = (JPanel) getContentPane();
syöte = new JTextField(10);
vastaus = new JLabel("tuntematon");
painike = new JButton("Laske");
painike.addActionListener(this);
syöte.addActionListener(this);
paneeli.setLayout(new FlowLayout(FlowLayout.LEFT, 10,10));
paneeli.add(syöte);
paneeli.add(vastaus);
paneeli.add(painike);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
vastaus.setText("" + ((Integer.parseInt(syöte.getText())*1.8+32)));
}
public static void main(String[] args){
Ikkuna i = new Ikkuna();
}
}
TLDR: Don't worry about it, it has nothing to do with your code, although you're probably better of removing Inquisitor extension as there's a good chance that it's not working properly.
InputManagers are intended to be Keyboard/Mouse extensions for applications. The idea is that the code is loaded into applications and can change their behavior in relation to Mouse/Keyboard input, but are generally used as a mechanism for extending applications. They became more restricted in 10.5, where they had to be in the system supported location only (/Library/InputManagers), and stopped being loaded entirely on 64bit mode.
Java 8 is a 64bit only application, so if you're seeing this error, then it's probably because the extension is not being loaded because it's a 64bit application and the system doesn't load extensions in this case.
The extension Inquisitor doesn't look to have been updated in a long time, and was used to extend the functionality of Safari, adding auto-complete to the search bar. The default search functionality of Safari now includes auto-complete, so I would consider it obsoleted.
If you want extended functionality for Safari, there are other plugins which extend the behaviour, such as Glims (I used to use it, but stopped because I felt it destabilized safari more than usual).
Opening the /Library/InputManagers folder (open a Finder window, hit Command-G to get a location field and type in the directory, then hit enter) will allow you to see what input managers are present on the system.

Java JNI: Creating a Swing Window using JNI from C

I'm using JNI to invoke a static java method which in turn creates a Swing JFrame and displays it. The code is fairly simple, and the Java-code is working standalone (i.e. java StartAWT does what it should) whereas when called from C using JNI the process hangs.
I'm using the JDK 1.7.0_09 on Mac OS X 10.8 Mountain Lion.
This is the C code I'm using to invoke the static method:
JavaVM* jvm;
JNIEnv* env = create_vm(&jvm);
jclass class = (*env)->FindClass(env, "StartAWT");
jmethodID method = (*env)->GetStaticMethodID(env, class, "run", "()V");
(*env)->CallStaticVoidMethod(env, class, method);
(*jvm)->DestroyJavaVM(jvm);
The StartAWT class looks like this:
public class StartAWT {
public static class Starter implements Runnable {
public void run() {
System.out.println("Runnning on AWT Queue.");
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("That's a frame!");
JLabel label = new JLabel("A Label");
frame.getContentPane().add(label);
frame.pack();
frame.setVisible(true);
}
}
public static class GUI implements Runnable {
public void run() {
try {
System.out.println("Going to put something on the AWT queue.");
SwingUtilities.invokeAndWait(new Starter());
} catch (Exception exc) {
throw new RuntimeException(exc);
}
}
}
public static void run() {
Thread gui = new Thread(new GUI());
gui.start();
}
}
When I start the application, I do see Going to put something on the AWT queue but not Running on AWT Queue.
I believe that the Virtual Machine inside my C Process does not have an AWT event queue but I don't know how to set it up for having one either (nor am I sure that this is the reason).
What is to be done in order to show an AWT based GUI using JNI ?
--
EDIT: I've inserted loops to see which threads are alive and which are not (can be seen in this gist). In this version I do the invocation of SwingUtilities.invokeAndWait in another thread. The result: The main thread is alive (C). The first thread dispatched by Java (not the main thread) is alive; the thread doing the Call invokeAndWait is blocked (I don't think that invokeAndWait did even return), the function which should be run on the EventQueue is not even entered.
I've also tried invoking SwingUtilities.invokeAndWait directly, which will give the following message:
2013-02-02 13:50:23.629 swing[1883:707] Cocoa AWT: Apple AWT Java VM was loaded on first thread -- can't start AWT. (
0 liblwawt.dylib 0x0000000117e87ad0 JNI_OnLoad + 468
1 libjava.dylib 0x00000001026076f1 Java_java_lang_ClassLoader_00024NativeLibrary_load + 207
2 ??? 0x000000010265af90 0x0 + 4335185808
)
This is also what I've read in other questions here on StackOverflow, such as the one suggested in the comments below. However, I could not find a solution to the original problem. Maybe it is worth noting that after the above message came up the main thread is still alive, i.e. neither did the process deadlock nor crash.
--
EDIT: I tested the code on Linux where it is working as expected. So I believe this is a Mac OS X issue with Cocoa AWT, but I don't know how to circumvent it.
--
EDIT: I also tried moving the entire invocation of the JVM onto a new native thread. This works on Mac OS X 10.6 with Apples Java 32-bit (1.6.0_37), but results in the same deadlock as described above. On Mac OS X 10.8 this is worse, the application crases with the only message "Trace/BPT trap: 5" (which seems to be related to loading dynamic libraries).
I also tried bundling the binary as described in this Q&A, but the launch fails with the message lsopenurlswithrole() failed with the message -10810, which is an unknown error, according to Apples Launch Services Reference. The latter also happens without attempting to use AWT (the mere JVM invocation fails).
Finally I found a solution.
The problem is not on which thread the Virtual Machine is being created, the problem is on which thread the AWT Event Queue is being initialized. In other words: The first time that an AWT class is loaded, it may not be loaded on the main thread. Thus step 1: Load (for example) java.awt.Component on another thread.
But now the EventQueue will block, as it delegates work to the Cocoa Main Event Queue which is not running - sure enough, since it will only run on the main thread and the main thread is my application. Thus the main run loop needs to be started on the main thread:
void
runCocoaMain()
{
void* clazz = objc_getClass("NSApplication");
void* app = objc_msgSend(clazz, sel_registerName("sharedApplication"));
objc_msgSend(app, sel_registerName("run"));
}
I had to link my application with the Cocoa framework and include <objc/objc-runtime.h>. The main thread is blocked after the call to runCocoaMain (since the event loop is running there), so one needs to resort to another thread for the application itself.
After running the EventQueue using the above snippet the loading of the AWT class on the other thread will succeed and you can proceed there.
I resolved similar problem by instructions of OSX: JavaVM, AWT/Swing and possibly a deadlock , that is to start CFRunLoopRun() after start JVM in another thread.

Categories

Resources